MIPS -gc-sections broken?

David Daney ddaney@caviumnetworks.com
Tue Jun 2 22:15:00 GMT 2009


Hiroki Kaminaga wrote:
> Hi,
> 
> While using -gc-sections option on MIPS ld, it seems that symbol which
> are in .bss section and is referenced by function that are to be removed
> by -gc-sections is not handled properly. Here is a sample. Binutils
> version used is 2.17.50.0.17, but I believe this happens in latest
> binutils too.
> 

That may be too old.  For anything other than small C programs with 
default linker options, I wouldn't use any binutils earlier than 2.19 
for MIPS/Linux.

David Daney


> 
>     *    *    *    *    *    *    *    *
> 
> $ cat foo.c
> int gbl_common[1800];
> 
> int func_not_called(void)
> {
>   return gbl_common[0];
> }
> 
> int foo(void) {
>   return 42;
> }
> 
> $ cat main.c 
> extern int foo(void);
> int main(void){
>   return foo();
> }
> 
> $ mips-unknown-linux-dev-gcc -ffunction-sections -fdata-sections -Wl,-gc-sections -o test foo.c main.c
> 
> (executing on MIPS target)
> # ./test 
> ./test: symbol lookup error: ./test: undefined symbol: gbl_common
> 
> 
>     *    *    *    *    *    *    *    *
> 
> Looking symbols by readelf gives
> 
> $ mips-unknown-linux-dev-readelf -s test | grep gbl_common
>      4: 00000000  7200 OBJECT  GLOBAL DEFAULT  ABS gbl_common
> 
> and does not belong to any section... gbl_common symbol should be
> removed, or at least have its entry in .bss section.
> Any hints, comments are appreciated!
> 
> Thanks in Advance,
> 
> 
> ----
> (Hiroki Kaminaga)
> t
> 



More information about the Binutils mailing list