tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] Overflows in the dynamic linker on x86_64 when using


From: ag
Subject: Re: [Tinycc-devel] Overflows in the dynamic linker on x86_64 when using a tcc-built shared library along with others
Date: Wed, 16 Oct 2019 20:18:21 +0300
User-agent: Mutt/1.12.1 (2019-06-15)

Hi,

As i'm getting the same error with Petr, this is a resurrection of an old thread
started at:

https://lists.nongnu.org/archive/html/tinycc-devel/2018-06/msg00009.html

On Tue, Jul 03, at 09:26 Petr Skočík wrote:
> I tracked down what was causing the "./a.out: Symbol `fstat' causes
> overflow in R_X86_64_PC32 relocation" message (and I suppose the others as
> well).
> 
> My build script attempts to link my executables with my project's dynamic
> lib (unless directed otherwise) and then a static version of the same lib
> before linking in external libs (the idea is to have a generic recipe that
> provides for the possibility that some of my project's executables might
> want to refer to project symbols that aren't exported in the shared lib).
> It seems it is this double linking ( `tcc something... liblib.so liblib.a`
> ), compounded with something in the glibc definition of
> fstat, that causes the problem on tcc.
> 
> MCVE:
> 
> #!/bin/sh -eu
> cat > liblib.c <<EOF
> #include <sys/stat.h>
> void f(void) { struct stat sb; fstat(0, &sb); }
> EOF
> cat > main.c <<EOF
> int main() { extern void f(); f(); return 0; }
> EOF
> : ${CC:=tcc}
> $CC liblib.c -fPIC -c; ar rcs liblib.a liblib.o; $CC -o liblib.so liblib.o
> -shared
> $CC main.c $PWD/liblib.so liblib.a #uncommenting liblib.a removes the error
> LD_LIBRARY_PATH=$PWD ./a.out
> 
> In the above reproducer, liblib.a should be ignored because it's not
> resolving any undefined references, but instead it appears to be causing
> the error message.

The following is reproducible on Linux running 4.12.10 on x86_64, with 
glibc-2.30:

cat > liblib.c <<EOF
#include <sys/stat.h>
void f (void) {
  struct stat sb;
  stat(0, &sb);
}
EOF

cat > main.c <<EOF

#include <sys/stat.h>

int main() {
   extern void f();
   f();
   struct stat st;
   stat ("/tmp", &st);
return 0;
}
EOF

tcc liblib.c -fPIC -shared -o liblib.so
tcc main.c -llib -L.
LD_LIBRARY_PATH=$PWD ./a.out

This fails with:
./a.out: Symbol `stat' causes overflow in R_X86_64_PC32 relocation

Any advice would be appreciated.

> Regards,
> Petr Skocik

Best,
  Αγαθοκλής



reply via email to

[Prev in Thread] Current Thread [Next in Thread]