From 77b530b50aedd1cf9943e1d4fdd97a364fe9a921 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 1 Dec 2017 11:59:14 -0500 Subject: [PATCH] updated embedded LLD to 5.0.1rc2 --- deps/lld-prebuilt/lld/Config/Version.inc | 4 +- deps/lld/COFF/Driver.cpp | 6 +- deps/lld/ELF/LinkerScript.cpp | 2 +- deps/lld/ELF/SyntheticSections.cpp | 12 +++- deps/lld/ELF/SyntheticSections.h | 3 +- deps/lld/lib/ReaderWriter/MachO/ArchHandler.h | 4 -- .../ReaderWriter/MachO/ArchHandler_arm.cpp | 4 -- .../ReaderWriter/MachO/ArchHandler_arm64.cpp | 4 -- .../ReaderWriter/MachO/ArchHandler_x86.cpp | 4 -- .../ReaderWriter/MachO/ArchHandler_x86_64.cpp | 6 +- .../MachO/MachONormalizedFileFromAtoms.cpp | 57 ----------------- .../test/ELF/eh-frame-padding-no-rosegment.s | 64 +++++++++++++++++++ deps/lld/test/mach-o/lazy-bind-x86_64.yaml | 4 +- 13 files changed, 85 insertions(+), 89 deletions(-) create mode 100644 deps/lld/test/ELF/eh-frame-padding-no-rosegment.s diff --git a/deps/lld-prebuilt/lld/Config/Version.inc b/deps/lld-prebuilt/lld/Config/Version.inc index 2fb8a16222..a3f6f44588 100644 --- a/deps/lld-prebuilt/lld/Config/Version.inc +++ b/deps/lld-prebuilt/lld/Config/Version.inc @@ -1,5 +1,5 @@ -#define LLD_VERSION 5.0.0 -#define LLD_VERSION_STRING "5.0.0" +#define LLD_VERSION 5.0.1 +#define LLD_VERSION_STRING "5.0.1" #define LLD_VERSION_MAJOR 5 #define LLD_VERSION_MINOR 0 #define LLD_REVISION_STRING "" diff --git a/deps/lld/COFF/Driver.cpp b/deps/lld/COFF/Driver.cpp index 0dabca6e37..854c3e6909 100644 --- a/deps/lld/COFF/Driver.cpp +++ b/deps/lld/COFF/Driver.cpp @@ -61,7 +61,6 @@ bool link(ArrayRef Args, raw_ostream &Diag) { (ErrorOS == &llvm::errs() && Process::StandardErrHasColors()); Driver = make(); Driver->link(Args); - freeArena(); return !ErrorCount; } @@ -1031,7 +1030,7 @@ void LinkerDriver::link(ArrayRef ArgsArr) { if (!Args.hasArgNoClaim(OPT_INPUT)) { fixupExports(); createImportLibrary(/*AsLib=*/true); - return; + exit(0); } // Handle /delayload @@ -1173,6 +1172,9 @@ void LinkerDriver::link(ArrayRef ArgsArr) { // Write the result. writeResult(&Symtab); + + // Call exit to avoid calling destructors. + exit(0); } } // namespace coff diff --git a/deps/lld/ELF/LinkerScript.cpp b/deps/lld/ELF/LinkerScript.cpp index 614f5e2c8b..8bdbd8db20 100644 --- a/deps/lld/ELF/LinkerScript.cpp +++ b/deps/lld/ELF/LinkerScript.cpp @@ -751,7 +751,7 @@ void LinkerScript::adjustSectionsAfterSorting() { if (auto *Cmd = dyn_cast(Base)) { Cmd->MemRegion = findMemoryRegion(Cmd); // Handle align (e.g. ".foo : ALIGN(16) { ... }"). - if (Cmd->AlignExpr && Cmd->Sec) + if (Cmd->AlignExpr) Cmd->Sec->updateAlignment(Cmd->AlignExpr().getValue()); } } diff --git a/deps/lld/ELF/SyntheticSections.cpp b/deps/lld/ELF/SyntheticSections.cpp index 4bbec4ab34..a67b039ddf 100644 --- a/deps/lld/ELF/SyntheticSections.cpp +++ b/deps/lld/ELF/SyntheticSections.cpp @@ -427,10 +427,11 @@ CieRecord *EhFrameSection::addCie(EhSectionPiece &Piece, &Sec->template getFile()->getRelocTargetSym(Rels[FirstRelI]); // Search for an existing CIE by CIE contents/relocation target pair. - CieRecord *Cie = &CieMap[{Piece.data(), Personality}]; + CieRecord *&Cie = CieMap[{Piece.data(), Personality}]; // If not found, create a new one. - if (Cie->Piece == nullptr) { + if (!Cie) { + Cie = make(); Cie->Piece = &Piece; Cies.push_back(Cie); } @@ -522,9 +523,14 @@ template static void writeCieFde(uint8_t *Buf, ArrayRef D) { memcpy(Buf, D.data(), D.size()); + size_t Aligned = alignTo(D.size(), sizeof(typename ELFT::uint)); + + // Zero-clear trailing padding if it exists. + memset(Buf + D.size(), 0, Aligned - D.size()); + // Fix the size field. -4 since size does not include the size field itself. const endianness E = ELFT::TargetEndianness; - write32(Buf, alignTo(D.size(), sizeof(typename ELFT::uint)) - 4); + write32(Buf, Aligned - 4); } template void EhFrameSection::finalizeContents() { diff --git a/deps/lld/ELF/SyntheticSections.h b/deps/lld/ELF/SyntheticSections.h index ddd8ca99a6..ccf021ec95 100644 --- a/deps/lld/ELF/SyntheticSections.h +++ b/deps/lld/ELF/SyntheticSections.h @@ -103,7 +103,8 @@ private: std::vector Cies; // CIE records are uniquified by their contents and personality functions. - llvm::DenseMap, SymbolBody *>, CieRecord> CieMap; + llvm::DenseMap, SymbolBody *>, CieRecord *> + CieMap; }; class GotSection : public SyntheticSection { diff --git a/deps/lld/lib/ReaderWriter/MachO/ArchHandler.h b/deps/lld/lib/ReaderWriter/MachO/ArchHandler.h index 6028006ca9..70a63bd100 100644 --- a/deps/lld/lib/ReaderWriter/MachO/ArchHandler.h +++ b/deps/lld/lib/ReaderWriter/MachO/ArchHandler.h @@ -112,10 +112,6 @@ public: /// info in final executables. virtual bool isLazyPointer(const Reference &); - /// Reference from an __stub_helper entry to the required offset of the - /// lazy bind commands. - virtual Reference::KindValue lazyImmediateLocationKind() = 0; - /// Returns true if the specified relocation is paired to the next relocation. virtual bool isPairedReloc(const normalized::Relocation &) = 0; diff --git a/deps/lld/lib/ReaderWriter/MachO/ArchHandler_arm.cpp b/deps/lld/lib/ReaderWriter/MachO/ArchHandler_arm.cpp index 2f663c660f..7d1544854c 100644 --- a/deps/lld/lib/ReaderWriter/MachO/ArchHandler_arm.cpp +++ b/deps/lld/lib/ReaderWriter/MachO/ArchHandler_arm.cpp @@ -67,10 +67,6 @@ public: return invalid; } - Reference::KindValue lazyImmediateLocationKind() override { - return lazyImmediateLocation; - } - Reference::KindValue pointerKind() override { return invalid; } diff --git a/deps/lld/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp b/deps/lld/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp index b9c815c5a3..10360b5c6d 100644 --- a/deps/lld/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp +++ b/deps/lld/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp @@ -127,10 +127,6 @@ public: return pointer64; } - Reference::KindValue lazyImmediateLocationKind() override { - return lazyImmediateLocation; - } - uint32_t dwarfCompactUnwindType() override { return 0x03000000; } diff --git a/deps/lld/lib/ReaderWriter/MachO/ArchHandler_x86.cpp b/deps/lld/lib/ReaderWriter/MachO/ArchHandler_x86.cpp index a2c6809272..2272bff65c 100644 --- a/deps/lld/lib/ReaderWriter/MachO/ArchHandler_x86.cpp +++ b/deps/lld/lib/ReaderWriter/MachO/ArchHandler_x86.cpp @@ -70,10 +70,6 @@ public: return delta32; } - Reference::KindValue lazyImmediateLocationKind() override { - return lazyImmediateLocation; - } - Reference::KindValue unwindRefToEhFrameKind() override { return invalid; } diff --git a/deps/lld/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp b/deps/lld/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp index efe23abb91..d687ca5de5 100644 --- a/deps/lld/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp +++ b/deps/lld/lib/ReaderWriter/MachO/ArchHandler_x86_64.cpp @@ -116,10 +116,6 @@ public: return unwindFDEToFunction; } - Reference::KindValue lazyImmediateLocationKind() override { - return lazyImmediateLocation; - } - Reference::KindValue unwindRefToEhFrameKind() override { return unwindInfoToEhFrame; } @@ -621,7 +617,7 @@ void ArchHandler_x86_64::applyFixupFinal( // Fall into llvm_unreachable(). break; } - return; + llvm_unreachable("invalid x86_64 Reference Kind"); } void ArchHandler_x86_64::applyFixupRelocatable(const Reference &ref, diff --git a/deps/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp b/deps/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp index f2e5ed7816..e58e3d2e7a 100644 --- a/deps/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp +++ b/deps/lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp @@ -172,8 +172,6 @@ private: SymbolScope &symbolScope); void appendSection(SectionInfo *si, NormalizedFile &file); uint32_t sectionIndexForAtom(const Atom *atom); - void fixLazyReferenceImm(const DefinedAtom *atom, uint32_t offset, - NormalizedFile &file); typedef llvm::DenseMap AtomToIndex; struct AtomAndIndex { const Atom *atom; uint32_t index; SymbolScope scope; }; @@ -1425,8 +1423,6 @@ void Util::addRebaseAndBindingInfo(const lld::File &atomFile, uint8_t segmentIndex; uint64_t segmentStartAddr; - uint32_t offsetInBindInfo = 0; - for (SectionInfo *sect : _sectionInfos) { segIndexForSection(sect, segmentIndex, segmentStartAddr); for (const AtomInfo &info : sect->atomsAndOffsets) { @@ -1471,59 +1467,6 @@ void Util::addRebaseAndBindingInfo(const lld::File &atomFile, bind.symbolName = targ->name(); bind.addend = ref->addend(); nFile.lazyBindingInfo.push_back(bind); - - // Now that we know the segmentOffset and the ordinal attribute, - // we can fix the helper's code - - fixLazyReferenceImm(atom, offsetInBindInfo, nFile); - - // 5 bytes for opcodes + variable sizes (target name + \0 and offset - // encode's size) - offsetInBindInfo += - 6 + targ->name().size() + llvm::getULEB128Size(bind.segOffset); - if (bind.ordinal > BIND_IMMEDIATE_MASK) - offsetInBindInfo += llvm::getULEB128Size(bind.ordinal); - } - } - } - } -} - -void Util::fixLazyReferenceImm(const DefinedAtom *atom, uint32_t offset, - NormalizedFile &file) { - for (const auto &ref : *atom) { - const DefinedAtom *da = dyn_cast(ref->target()); - if (da == nullptr) - return; - - const Reference *helperRef = nullptr; - for (const Reference *hr : *da) { - if (hr->kindValue() == _archHandler.lazyImmediateLocationKind()) { - helperRef = hr; - break; - } - } - if (helperRef == nullptr) - continue; - - // TODO: maybe get the fixed atom content from _archHandler ? - for (SectionInfo *sectInfo : _sectionInfos) { - for (const AtomInfo &atomInfo : sectInfo->atomsAndOffsets) { - if (atomInfo.atom == helperRef->target()) { - auto sectionContent = - file.sections[sectInfo->normalizedSectionIndex].content; - uint8_t *rawb = - file.ownedAllocations.Allocate(sectionContent.size()); - llvm::MutableArrayRef newContent{rawb, - sectionContent.size()}; - std::copy(sectionContent.begin(), sectionContent.end(), - newContent.begin()); - llvm::support::ulittle32_t *loc = - reinterpret_cast( - &newContent[atomInfo.offsetInSection + - helperRef->offsetInAtom()]); - *loc = offset; - file.sections[sectInfo->normalizedSectionIndex].content = newContent; } } } diff --git a/deps/lld/test/ELF/eh-frame-padding-no-rosegment.s b/deps/lld/test/ELF/eh-frame-padding-no-rosegment.s new file mode 100644 index 0000000000..951fed0a56 --- /dev/null +++ b/deps/lld/test/ELF/eh-frame-padding-no-rosegment.s @@ -0,0 +1,64 @@ +// REQUIRES: x86 + +.cfi_startproc +.cfi_personality 0x1b, bar +.cfi_endproc + +.global bar +.hidden bar +bar: + +// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o + +// Check the size of the CIE (0x18 + 4) and FDE (0x10 + 4) +// RUN: llvm-readobj -s -section-data %t.o | FileCheck --check-prefix=OBJ %s + +// OBJ: Name: .eh_frame +// OBJ-NEXT: Type: +// OBJ-NEXT: Flags [ +// OBJ-NEXT: SHF_ALLOC +// OBJ-NEXT: ] +// OBJ-NEXT: Address: +// OBJ-NEXT: Offset: +// OBJ-NEXT: Size: +// OBJ-NEXT: Link: +// OBJ-NEXT: Info: +// OBJ-NEXT: AddressAlignment: +// OBJ-NEXT: EntrySize: +// OBJ-NEXT: SectionData ( +// OBJ-NEXT: 0000: 18000000 00000000 017A5052 00017810 +// OBJ-NEXT: 0010: 061B0000 00001B0C 07089001 10000000 +// OBJ-NEXT: 0020: 20000000 00000000 00000000 00000000 +// OBJ-NEXT: ) + +// RUN: ld.lld %t.o -no-rosegment -o %t -shared + +// Check that .eh_frame is in the same segment as .text +// RUN: llvm-readobj -l --elf-output-style=GNU %t | FileCheck --check-prefix=PHDR %s + +// PHDR: Segment Sections +// PHDR: .text +// PHDR-SAME: .eh_frame + +// Check that the CIE and FDE are padded with 0x00 and not 0xCC when the +// .eh_frame section is placed in the executable segment +// RUN: llvm-readobj -s -section-data %t | FileCheck %s + +// CHECK: Name: .eh_frame +// CHECK-NEXT: Type: +// CHECK-NEXT: Flags +// CHECK-NEXT: SHF_ALLOC +// CHECK-NEXT: ] +// CHECK-NEXT: Address: +// CHECK-NEXT: Offset: +// CHECK-NEXT: Size: +// CHECK-NEXT: Link: +// CHECK-NEXT: Info: +// CHECK-NEXT: AddressAlignment: +// CHECK-NEXT: EntrySize: +// CHECK-NEXT: SectionData ( +// CHECK-NEXT: 0000: 1C000000 00000000 017A5052 00017810 +// CHECK-NEXT: 0010: 061BBEFF FFFF1B0C 07089001 00000000 +// CHECK-NEXT: 0020: 14000000 24000000 A8FFFFFF 00000000 +// CHECK-NEXT: 0030: 00000000 00000000 +// CHECK-NEXT: ) diff --git a/deps/lld/test/mach-o/lazy-bind-x86_64.yaml b/deps/lld/test/mach-o/lazy-bind-x86_64.yaml index 1322719e5f..5c588c5719 100644 --- a/deps/lld/test/mach-o/lazy-bind-x86_64.yaml +++ b/deps/lld/test/mach-o/lazy-bind-x86_64.yaml @@ -80,8 +80,8 @@ undefined-symbols: # CHECK-HELPERS:Disassembly of section __TEXT,__stub_helper: # CHECK-HELPERS: 68 00 00 00 00 pushq $0 -# CHECK-HELPERS: 68 0b 00 00 00 pushq $11 -# CHECK-HELPERS: 68 16 00 00 00 pushq $22 +# CHECK-HELPERS: 68 10 00 00 00 pushq $16 +# CHECK-HELPERS: 68 20 00 00 00 pushq $32 # Make sure the stub helper is correctly aligned # CHECK-DYLIBS: sectname __stub_helper