Currently, getFdePC() returns uint64_t. Its because the following
encodings might use 8 bytes: DW_EH_PE_absptr and DW_EH_PE_udata8.
But caller assigns returned value to uint32_t field:
https://github.com/llvm-mirror/lld/blob/master/ELF/SyntheticSections.cpp#L508
Value is used for building .eh_frame_hdr section.
We use DW_EH_PE_sdata4 encoding for building it at this moment:
https://github.com/llvm-mirror/lld/blob/master/ELF/SyntheticSections.cpp#L2545
And that means that an overflow issue might happen if
DW_EH_PE_absptr/DW_EH_PE_udata8 address encodings are present
in .eh_frame. In that case, before this patch, we silently would
truncate the address and produced broken .eh_frame_hdr section.
It would be not hard to support real 64-bit values for
DW_EH_PE_absptr/DW_EH_PE_udata8 encodings, but it is
unclear if it is usefull and if we should do it.
Since nobody faced/reported it, int this patch I only implement
a check to stop producing broken output silently for now.
llvm-svn: 337382
for (CieRecord *Rec : CieRecords) {
uint8_t Enc = getFdeEncoding(Rec->Cie);
for (EhSectionPiece *Fde : Rec->Fdes) {
- uint32_t Pc = getFdePc(Buf, Fde->OutputOff, Enc);
+ uint64_t Pc = getFdePc(Buf, Fde->OutputOff, Enc);
+ if (Pc > UINT32_MAX)
+ fatal(toString(Fde->Sec) + ": PC address is too large: " + Twine(Pc));
uint32_t FdeVA = getParent()->Addr + Fde->OutputOff;
- Ret.push_back({Pc, FdeVA});
+ Ret.push_back({(uint32_t)Pc, FdeVA});
}
}
return Ret;
--- /dev/null
+# REQUIRES: x86
+
+# 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
+
+.text
+.global foo
+foo:
+ nop
+
+.section .eh_frame, "a"
+ .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