This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

a linker error


Hi everyone
         I get the error " /usr/bin/ld: .libs/scan_sync_demo: hidden symbol `stat' in /usr/lib64/libc_nonshared.a(stat.oS) is referenced by DSO
                      /usr/bin/ld: final link failed: Nonrepresentable section on output ", 

The immediate cause is my XXX.so reference stat/fstat, but I find stat/fstat is not defined in XXX.so (by ldd âr)ã
[.libs]$ldd -r libobapi.so
        linux-vdso.so.1 =>  (0x00007ffff01ff000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fd5ca9fd000)
        librt.so.1 => /lib64/librt.so.1 (0x00007fd5ca7f5000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007fd5ca5f1000)
        libaio.so.1 => /lib64/libaio.so.1 (0x00007fd5ca3ef000)
        libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x00007fd5ca0e9000)
        libm.so.6 => /lib64/libm.so.6 (0x00007fd5c9e65000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fd5c9ad2000)
        /lib64/ld-linux-x86-64.so.2 (0x0000003b99400000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fd5c98bc000)
undefined symbol: stat  (./libobapi.so)
undefined symbol: fstat (./libobapi.so)

It is strange, xxx.so references /lib64/libc.so.6,  stat/fstat obviously belong libcãBut later I realize it is wrong,
[ .libs]$objdump -t /lib64/libc.so.6|grep fstat 
0000000000000000 l    df *ABS*  0000000000000000              fstatfs64.c
0000000000000000 l    df *ABS*  0000000000000000              fstatvfs.c
0000000000000000 l    df *ABS*  0000000000000000              fstatvfs64.c
0000003b99cd9eb0 l     F .text  0000000000000025              __GI_fstatfs64
0000003b99cd9f70 l     F .text  000000000000008c              __fstatvfs64
0000003b99cd9eb0 l     F .text  0000000000000025              __fstatfs
0000003b99cd9eb0 l     F .text  0000000000000025              __GI___fstatfs64
0000003b99cd9eb0 l     F .text  0000000000000025              __fstatfs64
0000003b99cd9f70 l     F .text  000000000000008c              __GI_fstatvfs
0000003b99cd9eb0 l     F .text  0000000000000025              __GI_fstatfs
0000003b99cd9eb0 l     F .text  0000000000000025              __GI___fstatfs
0000003b99cd9eb0  w    F .text  0000000000000025              fstatfs64
0000003b99cd9f70  w    F .text  000000000000008c              fstatvfs64
0000003b99cd9eb0  w    F .text  0000000000000025              fstatfs
0000003b99cd9f70 g     F .text  000000000000008c              fstatvfs

I canât find fstat/stat, but __fxstat/__xstat

[.libs]$objdump -t /lib64/libc.so.6|grep xstat                                    
ââ..
0000003b99cd9d20 g     F .text  0000000000000044              __lxstat
0000003b99cd9cd0 g     F .text  0000000000000044              __fxstat64
0000003b99cd9cd0 g     F .text  0000000000000044              __fxstat
0000003b99cd9d20 g     F .text  0000000000000044              __lxstat64
0000003b99cd9c80 g     F .text  0000000000000044              __xstat
0000003b99cd9c80 g     F .text  0000000000000044              __xstat64
0000003b99cd9e30 g     F .text  000000000000004c              __fxstatat64
0000003b99cd9e30 g     F .text  000000000000004c              __fxstatat

Where is fstat/stat? I read glibc source(v2.18), find
/* The `stat', `fstat', `lstat' functions have to be handled special since
   even while not compiling the library with optimization calls to these
   functions in the shared library must reference the `xstat' etc functions.
   We have to use macros but we cannot define them in the normal headers
   since on user level we must use real functions.  */
#define stat(fname, buf) __xstat (_STAT_VER, fname, buf)
#define lstat(fname, buf)  __lxstat (_STAT_VER, fname, buf)
#define __lstat(fname, buf)  __lxstat (_STAT_VER, fname, buf)
#define lstat64(fname, buf)  __lxstat64 (_STAT_VER, fname, buf)
#define __lstat64(fname, buf)  __lxstat64 (_STAT_VER, fname, buf)
#define stat64(fname, buf) __xstat64 (_STAT_VER, fname, buf)
#define fstat64(fd, buf) __fxstat64 (_STAT_VER, fd, buf)
#define __fstat64(fd, buf) __fxstat64 (_STAT_VER, fd, buf)
#define fstat(fd, buf) __fxstat (_STAT_VER, fd, buf)
#define __fstat(fd, buf) __fxstat (_STAT_VER, fd, buf)
#define __fstatat(dfd, fname, buf, flag) \
  __fxstatat (_STAT_VER, dfd, fname, buf, flag)
#define __fstatat64(dfd, fname, buf, flag) \
  __fxstatat64 (_STAT_VER, dfd, fname, buf, flag)

What does the comment means? I just know stat/fstat is macro from it.
My question is, why does stat/fstat appeared in xxx.so, why not replaced by __xstat/__fxstat in pre_process.


Here is a simple example.
Libfile.cpp
	#include <sys/stat.h>
	#include <sys/types.h>
	#include <unistd.h>

	void func()
	{
        	fstat(0,0);
        	stat(0, 0); 
	}


[test3]$g++ -fPIC libfile.cpp -c
test3]$objdump -t libfile.o 

libfile.o:     file format elf64-x86-64

SYMBOL TABLE:
0000000000000000 l    df *ABS*  0000000000000000 libfile.cpp
0000000000000000 l    d  .text  0000000000000000 .text
0000000000000000 l    d  .data  0000000000000000 .data
0000000000000000 l    d  .bss   0000000000000000 .bss
0000000000000000 l    d  .data.DW.ref.__gxx_personality_v0      0000000000000000 .data.DW.ref.__gxx_personality_v0
0000000000000000 l    d  .note.GNU-stack        0000000000000000 .note.GNU-stack
0000000000000000 l    d  .eh_frame      0000000000000000 .eh_frame
0000000000000000 l    d  .comment       0000000000000000 .comment
0000000000000000 l    d  .group 0000000000000000 .group
0000000000000000 g     F .text  0000000000000024 _Z4funcv
0000000000000000  w    O .data.DW.ref.__gxx_personality_v0      0000000000000008 .hidden DW.ref.__gxx_personality_v0
0000000000000000         *UND*  0000000000000000 _GLOBAL_OFFSET_TABLE_
0000000000000000         *UND*  0000000000000000 fstat
0000000000000000         *UND*  0000000000000000 stat
0000000000000000         *UND*  0000000000000000 __gxx_personality_v0    


[jienan.zjn@OceanBase036005 test3]$g++ -shared libfile.o -o libfile.so
[jienan.zjn@OceanBase036005 test3]$objdump -t libfile.so |grep stat
0000000000000690 l     F .text  000000000000000f              __fstat
0000000000000680 l     F .text  0000000000000010              __stat
0000000000000680 l     F .text  0000000000000010              stat
0000000000000690 l     F .text  000000000000000f              fstat
0000000000000000       F *UND*  0000000000000000              __xstat@@GLIBC_2.2.5
0000000000000000       F *UND*  0000000000000000              __fxstat@@GLIBC_2.2.5  


In this example, stat/fstat is defined in libfile.so. donât look like macro. I donât where I went wrong. Before emailing, I search similar questions, but I donât get what I wanted.

What more strange is

[jienan.zjn@OceanBase036005 test3]$g++ -fPIC libfile.cpp -c -O
[jienan.zjn@OceanBase036005 test3]$objdump -t libfile.o

libfile.o:     file format elf64-x86-64

SYMBOL TABLE:
0000000000000000 l    df *ABS*  0000000000000000 libfile.cpp
0000000000000000 l    d  .text  0000000000000000 .text
0000000000000000 l    d  .data  0000000000000000 .data
0000000000000000 l    d  .bss   0000000000000000 .bss
0000000000000000 l    d  .data.DW.ref.__gxx_personality_v0      0000000000000000 .data.DW.ref.__gxx_personality_v0
0000000000000000 l    d  .note.GNU-stack        0000000000000000 .note.GNU-stack
0000000000000000 l    d  .eh_frame      0000000000000000 .eh_frame
0000000000000000 l    d  .comment       0000000000000000 .comment
0000000000000000 l    d  .group 0000000000000000 .group
0000000000000000 g     F .text  0000000000000031 _Z4funcv
0000000000000000  w    O .data.DW.ref.__gxx_personality_v0      0000000000000008 .hidden DW.ref.__gxx_personality_v0
0000000000000000         *UND*  0000000000000000 _GLOBAL_OFFSET_TABLE_
0000000000000000         *UND*  0000000000000000 __fxstat     
0000000000000000         *UND*  0000000000000000 __xstat

stat/fstat disappeared.

Appreciate your reply! 



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]