Bug 59842 - `__x86.get_pc_thunk.bx' referenced in section `.text': defined in discarded section…
Summary: `__x86.get_pc_thunk.bx' referenced in section `.text': defined in discarded s...
Status: RESOLVED MOVED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.8.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-16 14:47 UTC by Thorsten Glaser
Modified: 2021-12-05 08:54 UTC (History)
0 users

See Also:
Host: i486-linux-gnu
Target: i486-linux-gnu
Build: i486-linux-gnu
Known to work: 3.4.6, 4.2.1, 4.6.4
Known to fail: 4.7.1, 4.8.2
Last reconfirmed:


Attachments
test runner (112 bytes, application/x-shellscript)
2014-01-16 14:47 UTC, Thorsten Glaser
Details
preprocessed source code (11.29 KB, text/plain)
2014-01-16 14:47 UTC, Thorsten Glaser
Details
symbols file (210 bytes, text/plain)
2014-01-16 14:50 UTC, Thorsten Glaser
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thorsten Glaser 2014-01-16 14:47:35 UTC
Created attachment 31855 [details]
test runner

Hi *,

I originally filed this as Debian #735564 but a user informed me they are also seeing this on other GNU/Linux distributions, and with GCC 4.7.1 on Slackware.

Since a while, I’m getting errors like these:

`__x86.get_pc_thunk.bx' referenced in section `.text' of x3.o: defined in discarded section `.text.__x86.get_pc_thunk.bx[__x86.get_pc_thunk.bx]' of x3.o

I used to be able to avoid them (although, back then, the symbol
was named “__i686.get_pc_thunk.bx”) by adding -march=i486, but
this no longer helps.

Screen log (the files x.sh, x.i and x.sym are attached):

tglase@tglase:~ $ mksh x.sh
`__x86.get_pc_thunk.bx' referenced in section `.text' of x3.o: defined in discarded section `.text.__x86.get_pc_thunk.bx[__x86.get_pc_thunk.bx]' of x3.o
`__x86.get_pc_thunk.bx' referenced in section `.text' of x3.o: defined in discarded section `.text.__x86.get_pc_thunk.bx[__x86.get_pc_thunk.bx]' of x3.o
`__x86.get_pc_thunk.bx' referenced in section `.text' of x3.o: defined in discarded section `.text.__x86.get_pc_thunk.bx[__x86.get_pc_thunk.bx]' of x3.o
`__x86.get_pc_thunk.bx' referenced in section `.text' of x3.o: defined in discarded section `.text.__x86.get_pc_thunk.bx[__x86.get_pc_thunk.bx]' of x3.o
`__x86.get_pc_thunk.bx' referenced in section `.text' of x3.o: defined in discarded section `.text.__x86.get_pc_thunk.bx[__x86.get_pc_thunk.bx]' of x3.o
`__x86.get_pc_thunk.bx' referenced in section `.text' of x3.o: defined in discarded section `.text.__x86.get_pc_thunk.bx[__x86.get_pc_thunk.bx]' of x3.o
`__x86.get_pc_thunk.bx' referenced in section `.text' of x3.o: defined in discarded section `.text.__x86.get_pc_thunk.bx[__x86.get_pc_thunk.bx]' of x3.o
`__x86.get_pc_thunk.bx' referenced in section `.text' of x3.o: defined in discarded section `.text.__x86.get_pc_thunk.bx[__x86.get_pc_thunk.bx]' of x3.o
`__x86.get_pc_thunk.bx' referenced in section `.text' of x3.o: defined in discarded section `.text.__x86.get_pc_thunk.bx[__x86.get_pc_thunk.bx]' of x3.o
`__x86.get_pc_thunk.bx' referenced in section `.text' of x3.o: defined in discarded section `.text.__x86.get_pc_thunk.bx[__x86.get_pc_thunk.bx]' of x3.o
`__x86.get_pc_thunk.bx' referenced in section `.text' of x3.o: defined in discarded section `.text.__x86.get_pc_thunk.bx[__x86.get_pc_thunk.bx]' of x3.o
collect2: error: ld returned 1 exit status

IMHO, GCC may not mark symbols as discardable that it uses by itself. Adding this to the symbol file is no solution either, as this becomes highly platform- and compiler-dependent.
Comment 1 Thorsten Glaser 2014-01-16 14:47:59 UTC
Created attachment 31856 [details]
preprocessed source code
Comment 2 Thorsten Glaser 2014-01-16 14:50:57 UTC
Created attachment 31857 [details]
symbols file
Comment 3 Thorsten Glaser 2014-01-16 14:58:31 UTC
Adding extra info. GCC 4.6 (Debian sid) works iff you add -march=i486 but exhibits the same problem (with different symbol) otherwise. GCC 3.4.6 (MirBSD) works.
Comment 4 Andrew Pinski 2014-01-16 16:46:31 UTC
I don't think this is a GCC bug but rather a bug using objcopy and thinking that will not get rid of hidden global symbols.

The .text.__x86.get_pc_thunk.[bc]x symbols are defined as:
        .section        .text.__x86.get_pc_thunk.cx,"axG",@progbits,__x86.get_pc_thunk.cx,comdat
        .globl  __x86.get_pc_thunk.cx
        .hidden __x86.get_pc_thunk.cx
        .type   __x86.get_pc_thunk.cx, @function
__x86.get_pc_thunk.cx:
.LFB15:
        .cfi_startproc
        movl    (%esp), %ecx
        ret
        .cfi_endproc
.LFE15:
        .section        .text.__x86.get_pc_thunk.bx,"axG",@progbits,__x86.get_pc_thunk.bx,comdat
        .globl  __x86.get_pc_thunk.bx
        .hidden __x86.get_pc_thunk.bx
        .type   __x86.get_pc_thunk.bx, @function
__x86.get_pc_thunk.bx:
.LFB16:
        .cfi_startproc
        movl    (%esp), %ebx
        ret

So they are already hidden so when doing the final link they will not show up in the shared library.  The objcopy is removing the symbol names for these section which is invalid as they are comdat and cannot be removed.


Really the code should move over to a versioning script instead of using objcopy and that would work much better and be slightly more portable.
Comment 5 Thorsten Glaser 2014-01-16 17:54:13 UTC
Hm, unsure. These versioning scripts are pretty much recent GNU stuff. But if you have input…

cvs -d _anoncvs@anoncvs.mirbsd.org:/cvs co -PA -d xchat-randex contrib/hosted/tg/code/xchat-randex
Comment 6 Andrew Pinski 2014-01-16 17:58:51 UTC
(In reply to Thorsten Glaser from comment #5)
> Hm, unsure. These versioning scripts are pretty much recent GNU stuff. 

Recent as in the last 10 years maybe.  But not in the last 5 years.  Also they are supported in Solaris and even Darwin too.
Comment 7 Andrew Pinski 2021-12-05 08:47:16 UTC
objcopy bug filed just recently:
https://sourceware.org/bugzilla/show_bug.cgi?id=27931

So closing as moved.
Comment 8 Andrew Pinski 2021-12-05 08:54:28 UTC
Or it is fixed by https://sourceware.org/bugzilla/show_bug.cgi?id=3182 .

Either way it is a binutils objcopy issue and not a GCC one really.