aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-12-02 12:47:20 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-12-02 12:47:20 +0000
commitd040441f934c022d291dd78321d95ff2bff27f05 (patch)
tree448ab0fbfc5895ee194074338621c92d0773d79e
parent43f6d9feefc874e8ad4e96f4b4c3c0713a29febe (diff)
downloadsrc-d040441f934c022d291dd78321d95ff2bff27f05.tar.gz
src-d040441f934c022d291dd78321d95ff2bff27f05.zip
Vendor import of lld release_50 branch r319231:vendor/lld/lld-release_50-r319231
Notes
Notes: svn path=/vendor/lld/dist/; revision=326467 svn path=/vendor/lld/lld-release_50-r319231/; revision=326468; tag=vendor/lld/lld-release_50-r319231
-rw-r--r--ELF/SyntheticSections.cpp12
-rw-r--r--ELF/SyntheticSections.h3
-rw-r--r--test/ELF/eh-frame-padding-no-rosegment.s64
3 files changed, 75 insertions, 4 deletions
diff --git a/ELF/SyntheticSections.cpp b/ELF/SyntheticSections.cpp
index 4bbec4ab34bd..a67b039ddf21 100644
--- a/ELF/SyntheticSections.cpp
+++ b/ELF/SyntheticSections.cpp
@@ -427,10 +427,11 @@ CieRecord *EhFrameSection<ELFT>::addCie(EhSectionPiece &Piece,
&Sec->template getFile<ELFT>()->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<CieRecord>();
Cie->Piece = &Piece;
Cies.push_back(Cie);
}
@@ -522,9 +523,14 @@ template <class ELFT>
static void writeCieFde(uint8_t *Buf, ArrayRef<uint8_t> 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<E>(Buf, alignTo(D.size(), sizeof(typename ELFT::uint)) - 4);
+ write32<E>(Buf, Aligned - 4);
}
template <class ELFT> void EhFrameSection<ELFT>::finalizeContents() {
diff --git a/ELF/SyntheticSections.h b/ELF/SyntheticSections.h
index ddd8ca99a61b..ccf021ec9597 100644
--- a/ELF/SyntheticSections.h
+++ b/ELF/SyntheticSections.h
@@ -103,7 +103,8 @@ private:
std::vector<CieRecord *> Cies;
// CIE records are uniquified by their contents and personality functions.
- llvm::DenseMap<std::pair<ArrayRef<uint8_t>, SymbolBody *>, CieRecord> CieMap;
+ llvm::DenseMap<std::pair<ArrayRef<uint8_t>, SymbolBody *>, CieRecord *>
+ CieMap;
};
class GotSection : public SyntheticSection {
diff --git a/test/ELF/eh-frame-padding-no-rosegment.s b/test/ELF/eh-frame-padding-no-rosegment.s
new file mode 100644
index 000000000000..951fed0a56e9
--- /dev/null
+++ b/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: )