[PATCH] D49607: [ELF] Check eh_frame_hdr overflow with PC offsets instead of PC absolute addresses
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 20 10:09:05 PDT 2018
MaskRay created this revision.
MaskRay added reviewers: grimar, ruiu.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D49607
Files:
ELF/SyntheticSections.cpp
ELF/SyntheticSections.h
test/ELF/eh-frame-pcaddr-overflow.s
Index: test/ELF/eh-frame-pcaddr-overflow.s
===================================================================
--- test/ELF/eh-frame-pcaddr-overflow.s
+++ test/ELF/eh-frame-pcaddr-overflow.s
@@ -3,7 +3,7 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
# RUN: not ld.lld --eh-frame-hdr --section-start .text=0x1000000000000000 \
# RUN: %t.o -o /dev/null 2>&1 | FileCheck %s
-# CHECK: error: {{.*}}.o:(.eh_frame): PC address is too large: 2387527121043355528
+# CHECK: error: {{.*}}.o:(.eh_frame): PC offset is too large: 0x1122334455666788
.text
.global foo
@@ -14,19 +14,19 @@
.long 12 # Size
.long 0x00 # ID
.byte 0x01 # Version.
-
+
.byte 0x52 # Augmentation string: 'R','\0'
.byte 0x00
-
+
.byte 0x01
-
+
.byte 0x01 # LEB128
.byte 0x01 # LEB128
.byte 0x00 # DW_EH_PE_absptr
.byte 0xFF
-
+
.long 12 # Size
.long 0x14 # ID
.quad foo + 0x1122334455667788
Index: ELF/SyntheticSections.h
===================================================================
--- ELF/SyntheticSections.h
+++ ELF/SyntheticSections.h
@@ -79,7 +79,7 @@
size_t NumFdes = 0;
struct FdeData {
- uint32_t Pc;
+ uint64_t Pc;
uint32_t FdeVA;
};
Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -502,14 +502,16 @@
uint8_t *Buf = getParent()->Loc + OutSecOff;
std::vector<FdeData> Ret;
+ uint64_t VA = InX::EhFrameHdr->getVA();
for (CieRecord *Rec : CieRecords) {
uint8_t Enc = getFdeEncoding(Rec->Cie);
for (EhSectionPiece *Fde : Rec->Fdes) {
uint64_t Pc = getFdePc(Buf, Fde->OutputOff, Enc);
- if (Pc > UINT32_MAX)
- fatal(toString(Fde->Sec) + ": PC address is too large: " + Twine(Pc));
+ if (Pc - VA != (uint64_t)signExtend(Pc - VA, 32))
+ fatal(toString(Fde->Sec) + ": PC offset is too large: 0x" +
+ Twine::utohexstr(Pc - VA));
uint32_t FdeVA = getParent()->Addr + Fde->OutputOff;
- Ret.push_back({(uint32_t)Pc, FdeVA});
+ Ret.push_back({Pc, FdeVA});
}
}
return Ret;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49607.156527.patch
Type: text/x-patch
Size: 2154 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180720/f620a2ef/attachment.bin>
More information about the llvm-commits
mailing list