[lld] 3822e3d - [lld-macho] Fix bug in handling unwind info from ld -r
Vy Nguyen via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 9 19:47:04 PDT 2021
Author: Vy Nguyen
Date: 2021-07-09T22:44:51-04:00
New Revision: 3822e3d5b049a23ac8ba78dd73767a490b678bd3
URL: https://github.com/llvm/llvm-project/commit/3822e3d5b049a23ac8ba78dd73767a490b678bd3
DIFF: https://github.com/llvm/llvm-project/commit/3822e3d5b049a23ac8ba78dd73767a490b678bd3.diff
LOG: [lld-macho] Fix bug in handling unwind info from ld -r
Two changess:
- Drop assertions that all symbols are in GOT
- Set allEntriesAreOmitted correctly
Related bug: 50812
Differential Revision: https://reviews.llvm.org/D105364
Added:
lld/test/MachO/relocs-syms-not-in-got.s
Modified:
lld/MachO/UnwindInfoSection.cpp
Removed:
################################################################################
diff --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp
index 6bd07c42af819..81a5064558aaa 100644
--- a/lld/MachO/UnwindInfoSection.cpp
+++ b/lld/MachO/UnwindInfoSection.cpp
@@ -167,9 +167,14 @@ void UnwindInfoSectionImpl<Ptr>::prepareRelocations(ConcatInputSection *isec) {
assert(target->hasAttr(r.type, RelocAttrBits::UNSIGNED));
if (r.offset % sizeof(CompactUnwindEntry<Ptr>) == 0) {
- if (auto *referentIsec = r.referent.dyn_cast<InputSection *>())
- if (!cast<ConcatInputSection>(referentIsec)->shouldOmitFromOutput())
- allEntriesAreOmitted = false;
+ InputSection *referentIsec;
+ if (auto *isec = r.referent.dyn_cast<InputSection *>())
+ referentIsec = isec;
+ else
+ referentIsec = cast<Defined>(r.referent.dyn_cast<Symbol *>())->isec;
+
+ if (!cast<ConcatInputSection>(referentIsec)->shouldOmitFromOutput())
+ allEntriesAreOmitted = false;
continue;
}
@@ -257,7 +262,6 @@ relocateCompactUnwind(ConcatOutputSection *compactUnwindSection,
uint64_t referentVA = TombstoneValue<Ptr>;
if (auto *referentSym = r.referent.dyn_cast<Symbol *>()) {
if (!isa<Undefined>(referentSym)) {
- assert(referentSym->isInGot());
if (auto *defined = dyn_cast<Defined>(referentSym))
checkTextSegment(defined->isec);
// At this point in the link, we may not yet know the final address of
diff --git a/lld/test/MachO/relocs-syms-not-in-got.s b/lld/test/MachO/relocs-syms-not-in-got.s
new file mode 100644
index 0000000000000..20a08152b36e9
--- /dev/null
+++ b/lld/test/MachO/relocs-syms-not-in-got.s
@@ -0,0 +1,101 @@
+# REQUIRES: x86
+## These yaml files were from an object file produced with 'ld -r', specifically:
+##
+## // foo.s
+## .text
+## .globl _main
+## _main:
+## .cfi_startproc
+## .cfi_def_cfa_offset 16
+## .cfi_endproc
+## nop
+##
+## llvm-mc -filetype=obj -triple=x86_64-apple-macos10.15 -o foo1.o foo.s
+## ld -r -o foo.o foo1.o
+
+
+# RUN: rm -rf %t; mkdir -p %t
+# RUN: yaml2obj %s -o %t/foo.o
+# RUN: %lld -o %t/a.out %t/foo.o
+
+--- !mach-o
+FileHeader:
+ magic: 0xFEEDFACF
+ cputype: 0x01000007
+ cpusubtype: 0x00000003
+ filetype: 0x00000001
+ ncmds: 2
+ sizeofcmds: 384
+ flags: 0x00000000
+ reserved: 0x00000000
+LoadCommands:
+ - cmd: LC_SEGMENT_64
+ cmdsize: 312
+ segname: ''
+ vmaddr: 0
+ vmsize: 64
+ fileoff: 448
+ filesize: 64
+ maxprot: 7
+ initprot: 7
+ nsects: 2
+ flags: 0
+ Sections:
+ - sectname: __text
+ segname: __TEXT
+ addr: 0x0000000000000000
+ size: 1
+ offset: 0x000001C0
+ align: 0
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x80000400
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ content: '90'
+ - sectname: __compact_unwind
+ segname: __LD
+ addr: 0x0000000000000020
+ size: 32
+ offset: 0x000001E0
+ align: 3
+ reloff: 0x00000200
+ nreloc: 1
+ flags: 0x02000000
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
+ content: '0000000000000000010000000000020200000000000000000000000000000000'
+ relocations:
+ - address: 0x00000000
+ symbolnum: 1
+ pcrel: false
+ length: 3
+ extern: true
+ type: 0
+ scattered: false
+ value: 0
+ - cmd: LC_SYMTAB
+ cmdsize: 24
+ symoff: 520
+ nsyms: 2
+ stroff: 552
+ strsize: 24
+LinkEditData:
+ NameList:
+ - n_strx: 8
+ n_type: 0x0E
+ n_sect: 2
+ n_desc: 0
+ n_value: 8
+ - n_strx: 2
+ n_type: 0x0F
+ n_sect: 1
+ n_desc: 32
+ n_value: 0
+ StringTable:
+ - ' '
+ - _main
+
+...
More information about the llvm-commits
mailing list