[PATCH] D27303: [ELF] - Implemented R_386_16 and R_386PC16 relocations
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 2 04:01:30 PST 2016
grimar updated this revision to Diff 80051.
grimar added a comment.
- Addressed review comments.
- Changed testcase to be single file and show how we truncate the value.
https://reviews.llvm.org/D27303
Files:
ELF/Target.cpp
test/ELF/i386-pc16.test
Index: test/ELF/i386-pc16.test
===================================================================
--- test/ELF/i386-pc16.test
+++ test/ELF/i386-pc16.test
@@ -0,0 +1,40 @@
+# REQUIRES: x86
+
+# RUN: yaml2obj %s -o %t.o
+# RUN: ld.lld %t.o -o %t.exe
+# RUN: llvm-objdump -s -section=.text %t.exe 2>&1 | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 11000 56441111 52341111
+
+!ELF
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_386
+Sections:
+ - Type: SHT_PROGBITS
+ Name: .text
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Content: "1111111111111111"
+ - Type: SHT_REL
+ Name: .rel.text
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0
+ Symbol: _start
+ Type: R_386_16
+ - Offset: 4
+ Symbol: _start
+ Type: R_386_PC16
+Symbols:
+ Global:
+ - Name: _start
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x12345
+ Size: 4
Index: ELF/Target.cpp
===================================================================
--- ELF/Target.cpp
+++ ELF/Target.cpp
@@ -329,6 +329,7 @@
return R_TLSLD;
case R_386_PLT32:
return R_PLT_PC;
+ case R_386_PC16:
case R_386_PC32:
return R_PC;
case R_386_GOTPC:
@@ -437,11 +438,13 @@
switch (Type) {
default:
return 0;
+ case R_386_16:
case R_386_32:
case R_386_GOT32:
case R_386_GOT32X:
case R_386_GOTOFF:
case R_386_GOTPC:
+ case R_386_PC16:
case R_386_PC32:
case R_386_PLT32:
case R_386_TLS_LE:
@@ -452,6 +455,13 @@
void X86TargetInfo::relocateOne(uint8_t *Loc, uint32_t Type,
uint64_t Val) const {
checkInt<32>(Loc, Val, Type);
+
+ // R_386_PC16 and R_386_16 are not part of the current i386 psABI. They are
+ // used by 16-bit x86 objects, like boot loaders.
+ if (Type == R_386_16 || Type == R_386_PC16) {
+ write16le(Loc, Val);
+ return;
+ }
write32le(Loc, Val);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27303.80051.patch
Type: text/x-patch
Size: 2218 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161202/17229757/attachment.bin>
More information about the llvm-commits
mailing list