This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
[PATCH] COFF symbol merging fix
- To: binutils at sources dot redhat dot com
- Subject: [PATCH] COFF symbol merging fix
- From: "Mark E." <snowball3 at bigfoot dot com>
- Date: Sun, 1 Jul 2001 15:12:38 -0400
Several DJGPP users have run into link problems with binutils 2.11 that
weren't present using 2.10. It turns out that a change somewhere else in
binutils sometimes causes coff symbols with debugging info to be merged when
they shouldn't.
A small C file:
void var(void)
{
return;
}
int main()
{
static int var;
return 0;
}
when compiled with 'gcc -g -S x.c' generates this assembly:
.file "x.c"
gcc2_compiled.:
___gnu_compiled_c:
.text
.p2align 2
.def _var; .val _var; .scl 2; .type 041; .endef
.globl _var
_var:
.def .bf; .val .; .scl 101; .line 2; .endef
pushl %ebp
movl %esp,%ebp
.ln 2
jmp L2
.ln 3
# .p2align 4,,7
L2:
movl %ebp,%esp
popl %ebp
ret
.def .ef; .val .; .scl 101; .line 3; .endef
.def _var; .val .; .scl -1; .endef
.lcomm _var.6,4
.p2align 2
.def _main; .val _main; .scl 2; .type 044; .endef
.globl _main
_main:
.def .bf; .val .; .scl 101; .line 7; .endef
pushl %ebp
movl %esp,%ebp
.ln 2
.def _var; .val _var.6; .scl 3; .type 04; .endef
.ln 4
xorl %eax,%eax
jmp L3
.ln 5
# .p2align 4,,7
L3:
movl %ebp,%esp
popl %ebp
ret
.def .ef; .val .; .scl 101; .line 5; .endef
.def _main; .val .; .scl -1; .endef
And with binutils 2.11, the nm listing is:
0000000c t .bf
00000000 t .bf
00000020 b .bss
00000020 d .data
00000017 t .ef
00000009 t .ef
00000000 t .text
00000000 t ___gnu_compiled_c
0000000c T _main
00000000 t _var
00000020 b _var.6
00000000 t gcc2_compiled.
Notice that the var from the function has been merged with the static
declaration of var from inside main. With the fix, nm produces the correct
listing:
0000000c t .bf
00000000 t .bf
00000020 b .bss
00000020 d .data
00000017 t .ef
00000009 t .ef
00000000 t .text
00000000 t ___gnu_compiled_c
0000000c T _main
00000020 b _var
00000000 T _var
00000020 b _var.6
00000000 t gcc2_compiled.
Please apply my fix if acceptable:
as/ChangeLog:
2001-07-01 Mark Elbrecht <snowball3@softhome.net>
* config/obj-coff.c (coff_frob_symbol): Don't merge if the storage
class of the non-debug symbol is C_NULL.
Index: obj-coff.c
===================================================================
RCS file: /cvs/src/src/gas/config/obj-coff.c,v
retrieving revision 1.49
diff -c -p -r1.49 obj-coff.c
*** obj-coff.c 2001/06/30 10:09:40 1.49
--- obj-coff.c 2001/07/01 18:10:28
*************** coff_frob_symbol (symp, punt)
*** 1180,1186 ****
&& S_GET_STORAGE_CLASS (symp) != C_LABEL
&& symbol_constant_p(symp)
&& (real = symbol_find_base (S_GET_NAME (symp), DO_NOT_STRIP))
! && real != symp)
{
c_symbol_merge (symp, real);
*punt = 1;
--- 1180,1187 ----
&& S_GET_STORAGE_CLASS (symp) != C_LABEL
&& symbol_constant_p(symp)
&& (real = symbol_find_base (S_GET_NAME (symp), DO_NOT_STRIP))
! && real != symp
! && S_GET_STORAGE_CLASS (real) == C_NULL)
{
c_symbol_merge (symp, real);
*punt = 1;