[llvm-bugs] [Bug 28779] New: Wrong relocation emitted using lld -r
via llvm-bugs
llvm-bugs at lists.llvm.org
Sat Jul 30 05:57:02 PDT 2016
https://llvm.org/bugs/show_bug.cgi?id=28779
Bug ID: 28779
Summary: Wrong relocation emitted using lld -r
Product: lld
Version: unspecified
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: ELF
Assignee: unassignedbugs at nondot.org
Reporter: rink at rink.nu
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
Created attachment 16842
--> https://llvm.org/bugs/attachment.cgi?id=16842&action=edit
Example code to trigger the bug (make LD=clang-lld)
When working on crt1 code for my own OS Ananas, I noticed the following (refer
to the attached archive): when you use 'lld -r' to combine object files, the
wrong offset is used. The attached example contains:
start.S: startup code, calls func() and exits
func.c: contains func() which initializes some value on stack and increments it
Makefile: compiles start.S -> start.o, func.c -> func.o, combines them to
'combined.o' and build 't' using 'combined.o'
Using LLD, the resulting program 't' crashes. This is because the offset of
'func' is wrong, as you can see when using objdump -d:
Disassembly of section .text:
0000000000011000 <_start>:
11000: e8 11 00 00 00 callq 11016 <func+0x4> <-- WRONG
11005: 48 c7 c0 3c 00 00 00 mov $0x3c,%rax
1100c: 48 31 ff xor %rdi,%rdi
1100f: 0f 05 syscall
11011: c3 retq
0000000000011012 <func>:
11012: 55 push %rbp
11013: 48 89 e5 mov %rsp,%rbp
11016: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp)
1101d: 83 45 fc 01 addl $0x1,-0x4(%rbp)
11021: 90 nop
11022: 5d pop %rbp
11023: c3 retq
Where GNU LD yields:
Disassembly of section .text:
00000000004000b0 <_start>:
4000b0: e8 0d 00 00 00 callq 4000c2 <func>
4000b5: 48 c7 c0 3c 00 00 00 mov $0x3c,%rax
4000bc: 48 31 ff xor %rdi,%rdi
4000bf: 0f 05 syscall
4000c1: c3 retq
00000000004000c2 <func>:
4000c2: 55 push %rbp
4000c3: 48 89 e5 mov %rsp,%rbp
4000c6: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp)
4000cd: 83 45 fc 01 addl $0x1,-0x4(%rbp)
4000d1: 90 nop
4000d2: 5d pop %rbp
4000d3: c3 retq
Note: I understand this is a silly example, but in my actual case combined.o
calls 'main' so I need to use -r because I want to build crt1.o.
--
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/20160730/f9266194/attachment.html>
More information about the llvm-bugs
mailing list