[LLVMbugs] [Bug 12440] New: Runtime linker issue with X11R6 on i386 with -O3 optimization
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Mon Apr 2 15:10:39 PDT 2012
http://llvm.org/bugs/show_bug.cgi?id=12440
Bug #: 12440
Summary: Runtime linker issue with X11R6 on i386 with -O3
optimization
Product: libraries
Version: trunk
Platform: PC
OS/Version: OpenBSD
Status: NEW
Severity: enhancement
Priority: P
Component: Backend: X86
AssignedTo: unassignedbugs at nondot.org
ReportedBy: marco at peereboom.us
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
Created attachment 8316
--> http://llvm.org/bugs/attachment.cgi?id=8316
lib a .i file
I was told to get this issue in the bug tracker so here goes.
The executive summary is that with any optimization higher than -O0 clang
generates code that is incompatible with X11's assumptions. When a TAILCALL is
generated it stuffs a function pointer into the GOT. When a library is
dlopen'ed it fails because it can't resolve the GOT function name.
This looks like a bug to me because the assumption that a function call is
resolved late is widely used in code that does "modules" of sorts.
Code was compiled on OpenBSD with clang 3.0-release and clang 3.1 trunk.
========================================================================
With -O0 which works as X expects:
========================================================================
$ make clean
rm -f a.o b.o liba.so libb.so app
$ make CFLAGS=-O0
clang -O0 -fpic -c a.c
clang -shared -o liba.so a.o
clang -O0 -fpic -c b.c
clang -shared -o libb.so b.o
clang -O0 -fpic app.c -o app
$ ./app
opening a
opening b
clang and X sitting in a tree :)
The relevant bits of objdump -R
$ objdump -R liba.so | grep ex_func
2000210c R_386_JUMP_SLOT ex_func
Looking at the asm here shows us that ex_func is always looked up in the
PLT.
$ grep ex_func a.s
calll ex_func at PLT
calll ex_func at PLT
========================================================================
With -O3 that doesn't work like X expects:
========================================================================
$ make clean
rm -f a.o b.o liba.so libb.so app
$ make CFLAGS=-O3
clang -O3 -fpic -c a.c
clang -shared -o liba.so a.o
clang -O3 -fpic -c b.c
clang -shared -o libb.so b.o
clang -O3 -fpic app.c -o app
$ ./app
opening a
./app:./liba.so: undefined symbol 'ex_func'
app: dlopen a Cannot load specified object
The relevant bits of objdump -R
$ objdump -R liba.so | grep ex_func
2000211c R_386_GLOB_DAT ex_func
20002108 R_386_JUMP_SLOT ex_func
Now in the asm here we can see that in the TAILCALL case the ex_func is
looked up in GOT.
$ grep ex_func a.s
calll ex_func at PLT
movl ex_func at GOT(%esi), %eax
...
jmpl *%eax # TAILCALL
See the attachments for the various temporary files and code.
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list