authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-10 13:25:20-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-09-10 13:25:20-04:00
loge92d74958c49e99953ddd5e2b92d0539a224174d
treee736c6631bdf56787fb8262ee5783c77cbe26881
parent016a59e3a155894412ccf3d98fe6ac1054243d06
signaturelock-open Commit is signed but in an unrecognized format.

lld: apply patch: [mach-o] Extend LC_DATA_IN_CODE support to x86_64

This applies 91864f82c7d7bd1a151fdfd076a3a67a2893b868 from LLVM trunk to the embedded LLD. Once Zig upgrades to LLD 10, there will be no difference between Zig's fork and upstream, and Zig's fork can be dropped.

1 files changed, 42 insertions(+), 8 deletions(-)

deps/lld/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp+42-8
...@@ -181,6 +181,20 @@ public:...@@ -181,6 +181,20 @@ public:
181 FindAddressForAtom addressForAtom,181 FindAddressForAtom addressForAtom,
182 normalized::Relocations &relocs) override;182 normalized::Relocations &relocs) override;
183183
184 bool isDataInCodeTransition(Reference::KindValue refKind) override {
185 return refKind == modeCode || refKind == modeData;
186 }
187
188 Reference::KindValue dataInCodeTransitionStart(
189 const MachODefinedAtom &atom) override {
190 return modeData;
191 }
192
193 Reference::KindValue dataInCodeTransitionEnd(
194 const MachODefinedAtom &atom) override {
195 return modeCode;
196 }
197
184private:198private:
185 static const Registry::KindStrings _sKindStrings[];199 static const Registry::KindStrings _sKindStrings[];
186 static const StubInfo _sStubInfo;200 static const StubInfo _sStubInfo;
...@@ -188,6 +202,9 @@ private:...@@ -188,6 +202,9 @@ private:
188 enum X86_64Kind: Reference::KindValue {202 enum X86_64Kind: Reference::KindValue {
189 invalid, /// for error condition203 invalid, /// for error condition
190204
205 modeCode, /// Content starting at this offset is code.
206 modeData, /// Content starting at this offset is data.
207
191 // Kinds found in mach-o .o files:208 // Kinds found in mach-o .o files:
192 branch32, /// ex: call _foo209 branch32, /// ex: call _foo
193 ripRel32, /// ex: movq _foo(%rip), %rax210 ripRel32, /// ex: movq _foo(%rip), %rax
...@@ -242,24 +259,34 @@ private:...@@ -242,24 +259,34 @@ private:
242};259};
243260
244const Registry::KindStrings ArchHandler_x86_64::_sKindStrings[] = {261const Registry::KindStrings ArchHandler_x86_64::_sKindStrings[] = {
245 LLD_KIND_STRING_ENTRY(invalid), LLD_KIND_STRING_ENTRY(branch32),262 LLD_KIND_STRING_ENTRY(invalid),
246 LLD_KIND_STRING_ENTRY(ripRel32), LLD_KIND_STRING_ENTRY(ripRel32Minus1),263 LLD_KIND_STRING_ENTRY(modeCode),
247 LLD_KIND_STRING_ENTRY(ripRel32Minus2), LLD_KIND_STRING_ENTRY(ripRel32Minus4),264 LLD_KIND_STRING_ENTRY(modeData),
265 LLD_KIND_STRING_ENTRY(branch32),
266 LLD_KIND_STRING_ENTRY(ripRel32),
267 LLD_KIND_STRING_ENTRY(ripRel32Minus1),
268 LLD_KIND_STRING_ENTRY(ripRel32Minus2),
269 LLD_KIND_STRING_ENTRY(ripRel32Minus4),
248 LLD_KIND_STRING_ENTRY(ripRel32Anon),270 LLD_KIND_STRING_ENTRY(ripRel32Anon),
249 LLD_KIND_STRING_ENTRY(ripRel32Minus1Anon),271 LLD_KIND_STRING_ENTRY(ripRel32Minus1Anon),
250 LLD_KIND_STRING_ENTRY(ripRel32Minus2Anon),272 LLD_KIND_STRING_ENTRY(ripRel32Minus2Anon),
251 LLD_KIND_STRING_ENTRY(ripRel32Minus4Anon),273 LLD_KIND_STRING_ENTRY(ripRel32Minus4Anon),
252 LLD_KIND_STRING_ENTRY(ripRel32GotLoad),274 LLD_KIND_STRING_ENTRY(ripRel32GotLoad),
253 LLD_KIND_STRING_ENTRY(ripRel32GotLoadNowLea),275 LLD_KIND_STRING_ENTRY(ripRel32GotLoadNowLea),
254 LLD_KIND_STRING_ENTRY(ripRel32Got), LLD_KIND_STRING_ENTRY(ripRel32Tlv),276 LLD_KIND_STRING_ENTRY(ripRel32Got),
277 LLD_KIND_STRING_ENTRY(ripRel32Tlv),
255 LLD_KIND_STRING_ENTRY(lazyPointer),278 LLD_KIND_STRING_ENTRY(lazyPointer),
256 LLD_KIND_STRING_ENTRY(lazyImmediateLocation),279 LLD_KIND_STRING_ENTRY(lazyImmediateLocation),
257 LLD_KIND_STRING_ENTRY(pointer64), LLD_KIND_STRING_ENTRY(pointer64Anon),280 LLD_KIND_STRING_ENTRY(pointer64),
258 LLD_KIND_STRING_ENTRY(delta32), LLD_KIND_STRING_ENTRY(delta64),281 LLD_KIND_STRING_ENTRY(pointer64Anon),
259 LLD_KIND_STRING_ENTRY(delta32Anon), LLD_KIND_STRING_ENTRY(delta64Anon),282 LLD_KIND_STRING_ENTRY(delta32),
283 LLD_KIND_STRING_ENTRY(delta64),
284 LLD_KIND_STRING_ENTRY(delta32Anon),
285 LLD_KIND_STRING_ENTRY(delta64Anon),
260 LLD_KIND_STRING_ENTRY(negDelta64),286 LLD_KIND_STRING_ENTRY(negDelta64),
261 LLD_KIND_STRING_ENTRY(negDelta32),287 LLD_KIND_STRING_ENTRY(negDelta32),
262 LLD_KIND_STRING_ENTRY(imageOffset), LLD_KIND_STRING_ENTRY(imageOffsetGot),288 LLD_KIND_STRING_ENTRY(imageOffset),
289 LLD_KIND_STRING_ENTRY(imageOffsetGot),
263 LLD_KIND_STRING_ENTRY(unwindFDEToFunction),290 LLD_KIND_STRING_ENTRY(unwindFDEToFunction),
264 LLD_KIND_STRING_ENTRY(unwindInfoToEhFrame),291 LLD_KIND_STRING_ENTRY(unwindInfoToEhFrame),
265 LLD_KIND_STRING_ENTRY(tlvInitSectionOffset),292 LLD_KIND_STRING_ENTRY(tlvInitSectionOffset),
...@@ -601,6 +628,8 @@ void ArchHandler_x86_64::applyFixupFinal(...@@ -601,6 +628,8 @@ void ArchHandler_x86_64::applyFixupFinal(
601 case negDelta32:628 case negDelta32:
602 *loc32 = fixupAddress - targetAddress + ref.addend();629 *loc32 = fixupAddress - targetAddress + ref.addend();
603 return;630 return;
631 case modeCode:
632 case modeData:
604 case lazyPointer:633 case lazyPointer:
605 // Do nothing634 // Do nothing
606 return;635 return;
...@@ -720,6 +749,8 @@ void ArchHandler_x86_64::applyFixupRelocatable(const Reference &ref,...@@ -720,6 +749,8 @@ void ArchHandler_x86_64::applyFixupRelocatable(const Reference &ref,
720 case unwindInfoToEhFrame:749 case unwindInfoToEhFrame:
721 llvm_unreachable("fixup implies __unwind_info");750 llvm_unreachable("fixup implies __unwind_info");
722 return;751 return;
752 case modeCode:
753 case modeData:
723 case unwindFDEToFunction:754 case unwindFDEToFunction:
724 // Do nothing for now755 // Do nothing for now
725 return;756 return;
...@@ -743,6 +774,9 @@ void ArchHandler_x86_64::appendSectionRelocations(...@@ -743,6 +774,9 @@ void ArchHandler_x86_64::appendSectionRelocations(
743 assert(ref.kindArch() == Reference::KindArch::x86_64);774 assert(ref.kindArch() == Reference::KindArch::x86_64);
744 uint32_t sectionOffset = atomSectionOffset + ref.offsetInAtom();775 uint32_t sectionOffset = atomSectionOffset + ref.offsetInAtom();
745 switch (static_cast<X86_64Kind>(ref.kindValue())) {776 switch (static_cast<X86_64Kind>(ref.kindValue())) {
777 case modeCode:
778 case modeData:
779 return;
746 case branch32:780 case branch32:
747 appendReloc(relocs, sectionOffset, symbolIndexForAtom(*ref.target()), 0,781 appendReloc(relocs, sectionOffset, symbolIndexForAtom(*ref.target()), 0,
748 X86_64_RELOC_BRANCH | rPcRel | rExtern | rLength4);782 X86_64_RELOC_BRANCH | rPcRel | rExtern | rLength4);