|Summary:||LD Does not Set GP Size of Archive Modules|
Description Evandro 2008-03-04 17:24:45 UTC
It seems that calling bfd_get_gp_size always returns 0 for a module found in an archive, no matter the value passed to LD via the -G option. The result is that when deciding whether to place public common symbols in the small BSS section or in the regular one, if such symbols reside in an archived module they are always placed in the regular BSS section.
Comment 3 Evandro 2008-03-04 17:29:00 UTC
Instructions to reproduce this issue: as d.s -o d.o as e.s -o e.o ar r e.a e.o The command below results in both "e4" and "ef" to be placed in .bss: ld d.o e.a Whereas the command below correctly places "e4" in .sbss: ld d.o e.o
Comment 4 H.J. Lu 2008-03-04 23:51:54 UTC
How can I reproduce it on Linux/x86-64? What target should I use? Linker manual says: `-GVALUE' `--gpsize=VALUE' Set the maximum size of objects to be optimized using the GP register to SIZE. This is only meaningful for object file formats such as MIPS ECOFF which supports putting large and small objects into different sections. This is ignored for other object file formats. Does it do anything for any ELF targets?
Comment 5 Evandro 2008-03-05 00:11:00 UTC
"-G size" sets the global g_switch_value in LD. This value is used to with bfd_set_gp_size in ldlang_add_file for regular modules. However, ldlang_add_file is never called for archived modules. Unfortunately, x86 doesn't have a GP register proper. MIPS and PPC and possibly IPF do though.
Comment 6 H.J. Lu 2008-03-05 01:07:42 UTC
(In reply to comment #5) > Unfortunately, x86 doesn't have a GP register proper. MIPS and PPC and possibly > IPF do though. > What is the expect result on MIPS/PPC/IPF?
Comment 7 Evandro 2008-03-06 17:45:26 UTC
Their ABIs are not specific, except that symbols referred to via the GP register must reside in the small data sections. In the case of common symbols, in .sbss, which doesn't happen at the moment if the symbol happens to be in an archive.
Comment 8 H.J. Lu 2008-03-07 04:11:51 UTC
(In reply to comment #3) > Instructions to reproduce this issue: > > as d.s -o d.o > as e.s -o e.o > ar r e.a e.o > > The command below results in both "e4" and "ef" to be placed in .bss: > > ld d.o e.a > > Whereas the command below correctly places "e4" in .sbss: > > ld d.o e.o > Your testcase is incorrect on ia64-linux, ppc-linux and mips-linux. I either got assembler error and linker error. Do you have a testcase for a supported binutils target?
Comment 9 H.J. Lu 2008-03-07 04:17:52 UTC
It works for me after a small change: bash-3.2$ cat d.s .extern e4, ef .comm d4, 4 .comm df, 15 .data .long e4 .long ef bash-3.2$ cat e.s .comm e4, 4 .comm ef, 15 bash-3.2$ make ./as -o e.o e.s ./as -o d.o d.s ./ld -G 16 -o good d.o e.o ./ld: warning: cannot find entry symbol _start; defaulting to 0000000010000054 ./ar -r e.a e.o ./ld -G 16 -o bad d.o e.a ./ld: warning: cannot find entry symbol _start; defaulting to 0000000010000054 cmp good bad bash-3.2$ ./ld -V GNU ld (GNU Binutils) 126.96.36.19980306 Supported emulations: elf32ppclinux elf32ppc elf32ppcsim bash-3.2$
Comment 10 Evandro 2008-03-07 04:57:05 UTC
Well, yes, the link is succesfull, but the problem is where common symbols in archived modules end up. Please, rerun ld with -G 8 and then run objdump on the output files and confirm that e4 is in .sbss and ef in .bss.
Comment 11 H.J. Lu 2008-03-07 06:00:13 UTC
(In reply to comment #10) > Well, yes, the link is succesfull, but the problem is where common symbols in > archived modules end up. > > Please, rerun ld with -G 8 and then run objdump on the output files and confirm > that e4 is in .sbss and ef in .bss. > Still works for me: bash-3.2$ make ./as -o e.o e.s ./as -o d.o d.s ./ld -G 8 -o good d.o e.o ./ld: warning: cannot find entry symbol _start; defaulting to 0000000010000054 ./ar -r e.a e.o ./ld -G 8 -o bad d.o e.a ./ld: warning: cannot find entry symbol _start; defaulting to 0000000010000054 cmp good bad bash-3.2$
Comment 12 Evandro 2008-03-07 16:46:23 UTC
Could you please e-mail me "good" and "bad"? I wonder if PPC is similar to MIPS in using small data sections.
Comment 13 H.J. Lu 2008-03-07 16:53:26 UTC
(In reply to comment #12) > Could you please e-mail me "good" and "bad"? I wonder if PPC is similar to MIPS > in using small data sections. "good" and "bad" are identical: bash-3.2$ readelf -Ss good There are 7 section headers, starting at offset 0x88: Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [ 0] NULL 00000000 000000 000000 00 0 0 0 [ 1] .data PROGBITS 10010054 000054 000008 00 WA 0 0 1 [ 2] .sbss NOBITS 1001005c 00005c 000008 00 WA 0 0 4 [ 3] .bss NOBITS 10010068 00005c 000020 00 WA 0 0 8 [ 4] .shstrtab STRTAB 00000000 00005c 00002c 00 0 0 1 [ 5] .symtab SYMTAB 00000000 0001a0 0000b0 10 6 4 4 [ 6] .strtab STRTAB 00000000 000250 000025 00 0 0 1 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings) I (info), L (link order), G (group), x (unknown) O (extra OS processing required) o (OS specific), p (processor specific) Symbol table '.symtab' contains 11 entries: Num: Value Size Type Bind Vis Ndx Name 0: 00000000 0 NOTYPE LOCAL DEFAULT UND 1: 10010054 0 SECTION LOCAL DEFAULT 1 2: 1001005c 0 SECTION LOCAL DEFAULT 2 3: 10010068 0 SECTION LOCAL DEFAULT 3 4: 10010078 15 OBJECT GLOBAL DEFAULT 3 ef 5: 10010068 15 OBJECT GLOBAL DEFAULT 3 df 6: 10010060 4 OBJECT GLOBAL DEFAULT 2 e4 7: 1001005c 0 NOTYPE GLOBAL DEFAULT ABS __bss_start 8: 1001005c 4 OBJECT GLOBAL DEFAULT 2 d4 9: 1001005c 0 NOTYPE GLOBAL DEFAULT ABS _edata 10: 10010088 0 NOTYPE GLOBAL DEFAULT ABS _end bash-3.2$ ef is in .bss since its size, 15, > 8. e4 is in .sbss since its size, 4, <= 8.
Comment 14 Alan Modra 2009-01-24 04:42:51 UTC
I could not reproduce this on either powerpc-linux or mips-linux.