[llvm-bugs] [Bug 28924] New: Missing relocations when linking i686 with -fpie
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Aug 10 09:12:11 PDT 2016
https://llvm.org/bugs/show_bug.cgi?id=28924
Bug ID: 28924
Summary: Missing relocations when linking i686 with -fpie
Product: lld
Version: unspecified
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: ELF
Assignee: unassignedbugs at nondot.org
Reporter: llvm at sjor.sg
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
Compiling for i686-unknown-linux-gnu with -fpie, it looks like lld is missing
some relocations, or applying them incorrectly, causing the use of external
global variables to fail. I boiled a bug down to this, but am not sure if I can
go further, as this is starting to go well outside my expertise.
This is using LLVM r278216, Clang r278213, LLD r278205.
Thanks for investigating!
-------8<-------
$ cat header.h
extern int (*global_function)();
static inline int do_global_call() {
return global_function();
}
$ cat unit1.c
#include "header.h"
#include <stdio.h>
int (*global_function)();
int global_implementation() {
return 1234;
}
void cu2_call();
int main() {
global_function = global_implementation;
printf("Global call value: %d\n", do_global_call());
cu2_call();
}
$ cat unit2.c
#include "header.h"
#include <stdio.h>
void cu2_call() {
printf("Compilation unit 2 global call value: %d\n", do_global_call());
}
$ i686-unknown-linux-gnu-clang -Wall -fpie unit1.c -c -o unit1.o
$ i686-unknown-linux-gnu-clang -Wall -fpie unit2.c -c -o unit2.o
$ i686-unknown-linux-gnu-clang -fpie -fuse-ld=lld
-Wl,--allow-multiple-definition unit1.o unit2.o -o testbin.lld
duplicate symbol: __x86.get_pc_thunk.bx in
/usr/lib/gcc/i586-linux-gnu/4.9/../../../i386-linux-gnu/crti.o and
/usr/lib/i386-linux-gnu/libc_nonshared.a(elf-init.oS)
$ i686-unknown-linux-gnu-clang -fpie unit1.o unit2.o -o testbin.gld
$ ./testbin.lld
Global call value: 1234
[1] 21726 segmentation fault ./testbin.lld
$ ./testbin.gld
Global call value: 1234
Compilation unit 2 global call value: 1234
-------8<------
$ readelf -r testbin.lld
Relocation section '.rel.plt' at offset 0x36c contains 2 entries:
Offset Info Type Sym.Value Sym. Name
00013014 00000307 R_386_JUMP_SLOT 000112c0 __libc_start_main
00013018 00000207 R_386_JUMP_SLOT 00000000 printf
$ readelf -r testbin.gld
Relocation section '.rel.dyn' at offset 0x278 contains 1 entries:
Offset Info Type Sym.Value Sym. Name
08049784 00000206 R_386_GLOB_DAT 00000000 __gmon_start__
Relocation section '.rel.plt' at offset 0x280 contains 3 entries:
Offset Info Type Sym.Value Sym. Name
08049794 00000107 R_386_JUMP_SLOT 00000000 printf
08049798 00000207 R_386_JUMP_SLOT 00000000 __gmon_start__
0804979c 00000307 R_386_JUMP_SLOT 00000000 __libc_start_main
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160810/7bd7045e/attachment-0001.html>
More information about the llvm-bugs
mailing list