bebbo / binutils-gdb

Unofficial mirror of sourceware binutils-gdb repository. Updated daily.
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git
GNU General Public License v2.0
3 stars 3 forks source link

Removal of non-empty section by amiga binutils assembler #1

Closed PierreMuller closed 5 years ago

PierreMuller commented 5 years ago

Hi,

I am using your branch of binutils to test Free Pascal for m68k amiga target.

The following simple assembler source:

start of testas.as .data .globl DEBUGINFO$WPO DEBUGINFO$WPO: end of file

leads to an object file in which the global symbol is removed.

m68k-amigasos-as -o test-as.o test-as.as

The reason is that the section .data is removed because its size is zero, but the fact that it does contain a global symbol is not considered.

Other variants of binutils, including recent releases never showed this behavior. I now that it is strange to define a global symbol in an empty section, but currently Free Pascal does rely on the fact that even if empty the section will not be removed if it contains a global symbol.

Should this be considered as a bug in your code or in Free Pascal?

Pierre Muller

(gdb) b remove_section_index Breakpoint 1 at 0x8e845: file /home/muller/gnu/amiga/amiga-gcc/projects/binutils/bfd/amigaos.c, line 1635. (gdb) r Starting program: /home/muller/gnu/bin/m68k-amigaos-as -o test.o test-as.as

Breakpoint 1, remove_section_index (sec=0x5555558b0450, index_map=0x5555558efc48) at /home/muller/gnu/amiga/amiga-gcc/projects/binutils/bfd/amigaos.c:1635 1635 int i=sec->index; (gdb) p *sec $1 = {name = 0x55555562cce8 ".data", id = 17, index = 1, next = 0x5555558b0580, prev = 0x5555558b0320, flags = 35, user_set_vma = 0, linker_mark = 0, linker_has_input = 0, gc_mark = 0, compress_status = 0, segment_mark = 0, sec_info_type = 0, use_rela_p = 0, sec_flg0 = 0, sec_flg1 = 0, sec_flg2 = 0, sec_flg3 = 0, sec_flg4 = 0, sec_flg5 = 0, vma = 0, lma = 0, size = 0, rawsize = 0, compressed_size = 0, relax = 0x0, relax_count = 0, output_offset = 0, output_section = 0x5555558b0450, alignment_power = 2, relocation = 0x0, orelocation = 0x0, reloc_count = 0, filepos = 0, rel_filepos = 0, line_filepos = 0, userdata = 0x5555558b2500, contents = 0x0, lineno = 0x0, lineno_count = 0, entsize = 0, kept_section = 0x0, moving_line_filepos = 0, target_index = 0, used_by_bfd = 0x5555558af4e0, constructor_chain = 0x0, owner = 0x5555558af180, symbol = 0x5555558af498, symbol_ptr_ptr = 0x5555558b0548, map_head = {link_order = 0x0, s = 0x0}, map_tail = {link_order = 0x0, s = 0x0}} (gdb) bt

0 remove_section_index (sec=0x5555558b0450, index_map=0x5555558efc48) at /home/muller/gnu/amiga/amiga-gcc/projects/binutils/bfd/amigaos.c:1635

1 0x00005555555e3180 in amiga_write_object_contents (abfd=0x5555558af180) at /home/muller/gnu/amiga/amiga-gcc/projects/binutils/bfd/amigaos.c:1830

2 0x00005555555d92b6 in bfd_close (abfd=0x5555558af180) at /home/muller/gnu/amiga/amiga-gcc/projects/binutils/bfd/opncls.c:731

3 0x00005555555a6e6d in output_file_close (filename=0x555555899ec0 "test.o") at /home/muller/gnu/amiga/amiga-gcc/projects/binutils/gas/output-file.c:64

4 0x000055555558ef0f in close_output_file () at /home/muller/gnu/amiga/amiga-gcc/projects/binutils/gas/as.c:1105

5 0x000055555562ad93 in xatexit_cleanup () at /home/muller/gnu/amiga/amiga-gcc/projects/binutils/libiberty/xatexit.c:101

6 0x000055555562adca in xexit (code=0) at /home/muller/gnu/amiga/amiga-gcc/projects/binutils/libiberty/xexit.c:50

7 0x000055555558f781 in main (argc=2, argv=0x555555899e90) at /home/muller/gnu/amiga/amiga-gcc/projects/binutils/gas/as.c:1464

(gdb) f 1

1 0x00005555555e3180 in amiga_write_object_contents (abfd=0x5555558af180) at /home/muller/gnu/amiga/amiga-gcc/projects/binutils/bfd/amigaos.c:1830

1830 remove_section_index (p, index_map); (gdb) li 1825 } 1826 1827 for (p = abfd->sections; p != NULL; p = p->next) 1828 { 1829 if (p->rawsize == 0 && p->size == 0 && strcmp (".text", p->name)) 1830 remove_section_index (p, index_map); 1831 } 1832 } 1833 1834 / Compute the maximum hunk number of the ouput file /

PierreMuller commented 5 years ago

I checked binutils 2.28 for x8664-linux-gnu, and it does not seem to remove any section, not even a completely empty one. With this source: .data .globl DEBUGINFO$WPO DEBUGINFO_$WPO:

.section .data2

the generated object also contains a .data2 section.

bebbo commented 5 years ago

please test.

I hope that change does not break anything else... :-)

bebbo commented 5 years ago
x.o:     file format amiga
x.o
architecture: m68k:68000, flags 0x00000010:
HAS_SYMS
start address 0x00000000

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000000  00000000  00000000  00000024  2**2
                  CONTENTS, ALLOC, LOAD, CODE
  1 .data         00000000  00000000  00000000  00000040  2**2
                  CONTENTS, ALLOC, LOAD, DATA
SYMBOL TABLE:
00000000 g       .data      0000 01 DEBUGINFO_$WPO
PierreMuller commented 5 years ago

Fix confirmed!

Thanks a lot for the fast feedback!