diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 1e66f51..1a9a055 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -317,8 +317,8 @@ void elf::ObjectFile::initializeSections( } // .ARM.exidx sections have a reverse dependency on the InputSection they - // have a SHF_LINK_ORDER dependency, this is identified by the sh_link. - if (Sec.sh_flags & SHF_LINK_ORDER) { + // have a SHF_METADATA dependency, this is identified by the sh_link. + if (Sec.sh_flags & SHF_METADATA) { if (Sec.sh_link >= Sections.size()) fatal(toString(this) + ": invalid sh_link index: " + Twine(Sec.sh_link)); diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index e8f24e1..00271cf9 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -156,7 +156,7 @@ InputSectionBase::getOffset(const DefinedRegular &Sym) const { template InputSectionBase *InputSectionBase::getLinkOrderDep() const { - if ((Flags & SHF_LINK_ORDER) && Link != 0) + if ((Flags & SHF_METADATA) && Link != 0) return getFile()->getSections()[Link]; return nullptr; } diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 6de3044..e268e08 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -102,13 +102,13 @@ static bool compareByFilePosition(InputSection *A, } template void OutputSection::finalize() { - if ((this->Flags & SHF_LINK_ORDER) && !this->Sections.empty()) { + if ((this->Flags & SHF_METADATA) && !this->Sections.empty()) { std::sort(Sections.begin(), Sections.end(), compareByFilePosition); Size = 0; assignOffsets(); // We must preserve the link order dependency of sections with the - // SHF_LINK_ORDER flag. The dependency is indicated by the sh_link field. We + // SHF_METADATA flag. The dependency is indicated by the sh_link field. We // need to translate the InputSection sh_link to the OutputSection sh_link, // all InputSections in the OutputSection have the same dependency. if (auto *D = this->Sections.front()->getLinkOrderDep()) diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp index 58a75c5..c7fdbc5 100644 --- a/lld/ELF/SyntheticSections.cpp +++ b/lld/ELF/SyntheticSections.cpp @@ -1957,7 +1957,7 @@ template void MipsRldMapSection::writeTo(uint8_t *Buf) { template ARMExidxSentinelSection::ARMExidxSentinelSection() - : SyntheticSection(SHF_ALLOC | SHF_LINK_ORDER, SHT_ARM_EXIDX, + : SyntheticSection(SHF_ALLOC | SHF_METADATA, SHT_ARM_EXIDX, sizeof(typename ELFT::uint), ".ARM.exidx") {} // Write a terminating sentinel entry to the end of the .ARM.exidx table. diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index a3887f3..ffb41dd 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -935,7 +935,7 @@ static bool canSharePtLoad(const OutputSectionBase &S1, template void Writer::sortSections() { // Don't sort if using -r. It is not necessary and we want to preserve the - // relative order for SHF_LINK_ORDER sections. + // relative order for SHF_METADATA sections. if (Config->Relocatable) return; if (!ScriptConfig->HasSections) { diff --git a/lld/test/ELF/Inputs/arm-exidx-cantunwind.s b/lld/test/ELF/Inputs/arm-exidx-cantunwind.s index 679cc75..b24fdd0 100644 --- a/lld/test/ELF/Inputs/arm-exidx-cantunwind.s +++ b/lld/test/ELF/Inputs/arm-exidx-cantunwind.s @@ -1,4 +1,4 @@ -// Functions that will generate a .ARM.exidx section with SHF_LINK_ORDER +// Functions that will generate a .ARM.exidx section with SHF_METADATA // dependency on the progbits section containing the .cantunwind directive .syntax unified .section .func1, "ax",%progbits diff --git a/lld/test/ELF/arm-exidx-canunwind.s b/lld/test/ELF/arm-exidx-canunwind.s index e98ec0e..549e8f9 100644 --- a/lld/test/ELF/arm-exidx-canunwind.s +++ b/lld/test/ELF/arm-exidx-canunwind.s @@ -80,7 +80,7 @@ _start: // CHECK-PT-NEXT: Type: SHT_ARM_EXIDX (0x70000001) // CHECK-PT-NEXT: Flags [ // CHECK-PT-NEXT: SHF_ALLOC -// CHECK-PT-NEXT: SHF_LINK_ORDER +// CHECK-PT-NEXT: SHF_METADATA // CHECK-PT-NEXT: ] // CHECK-PT-NEXT: Address: 0x100D4 // CHECK-PT-NEXT: Offset: 0xD4 diff --git a/lld/test/ELF/arm-exidx-link.s b/lld/test/ELF/arm-exidx-link.s index 50f9812..e742779 100644 --- a/lld/test/ELF/arm-exidx-link.s +++ b/lld/test/ELF/arm-exidx-link.s @@ -7,7 +7,7 @@ // CHECK-NEXT: Type: SHT_ARM_EXIDX // CHECK-NEXT: Flags [ // CHECK-NEXT: SHF_ALLOC -// CHECK-NEXT: SHF_LINK_ORDER +// CHECK-NEXT: SHF_METADATA // CHECK-NEXT: ] // CHECK-NEXT: Address: // CHECK-NEXT: Offset: diff --git a/lld/test/ELF/arm-exidx-order.s b/lld/test/ELF/arm-exidx-order.s index 951c71a..30d29eb 100644 --- a/lld/test/ELF/arm-exidx-order.s +++ b/lld/test/ELF/arm-exidx-order.s @@ -13,7 +13,7 @@ // RUN: llvm-objdump -s -triple=armv7a-none-linux-gnueabi %t3 | FileCheck -check-prefix=CHECK-SCRIPT-EXIDX %s // REQUIRES: arm -// Each assembler created .ARM.exidx section has the SHF_LINK_ORDER flag set +// Each assembler created .ARM.exidx section has the SHF_METADATA flag set // with the sh_link containing the section index of the executable section // containing the function it describes. The linker must combine the .ARM.exidx // InputSections in the same order that it has combined the executable section, @@ -105,7 +105,7 @@ f3: // CHECK-PT-NEXT: Type: SHT_ARM_EXIDX (0x70000001) // CHECK-PT-NEXT: Flags [ // CHECK-PT-NEXT: SHF_ALLOC -// CHECK-PT-NEXT: SHF_LINK_ORDER +// CHECK-PT-NEXT: SHF_METADATA // CHECK-PT-NEXT: ] // CHECK-PT-NEXT: Address: 0x100D4 // CHECK-PT-NEXT: Offset: 0xD4 diff --git a/lld/test/ELF/arm-exidx-output.s b/lld/test/ELF/arm-exidx-output.s index dca43a3..0721718 100644 --- a/lld/test/ELF/arm-exidx-output.s +++ b/lld/test/ELF/arm-exidx-output.s @@ -37,7 +37,7 @@ f2: // CHECK-NEXT: Type: SHT_ARM_EXIDX (0x70000001) // CHECK-NEXT: Flags [ // CHECK-NEXT: SHF_ALLOC -// CHECK-NEXT: SHF_LINK_ORDER +// CHECK-NEXT: SHF_METADATA // CHECK-NEXT: ] // CHECK-NOT: Name: .ARM.exidx.text.f1 diff --git a/lld/test/ELF/arm-exidx-relocatable.s b/lld/test/ELF/arm-exidx-relocatable.s index 1b6ee3f..9902299 100644 --- a/lld/test/ELF/arm-exidx-relocatable.s +++ b/lld/test/ELF/arm-exidx-relocatable.s @@ -1,11 +1,11 @@ // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t // RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %S/Inputs/arm-exidx-cantunwind.s -o %tcantunwind -// Check that relocatable link maintains SHF_LINK_ORDER +// Check that relocatable link maintains SHF_METADATA // RUN: ld.lld -r %t %tcantunwind -o %t4 2>&1 // RUN: llvm-readobj -s %t4 | FileCheck %s // REQUIRES: arm -// Each assembler created .ARM.exidx section has the SHF_LINK_ORDER flag set +// Each assembler created .ARM.exidx section has the SHF_METADATA flag set // with the sh_link containing the section index of the executable section // containing the function it describes. To maintain this property in // relocatable links we pass through the .ARM.exidx section, the section it @@ -49,7 +49,7 @@ f3: // CHECK-NEXT: Type: SHT_ARM_EXIDX (0x70000001) // CHECK-NEXT: Flags [ (0x82) // CHECK-NEXT: SHF_ALLOC (0x2) -// CHECK-NEXT: SHF_LINK_ORDER (0x80) +// CHECK-NEXT: SHF_METADATA (0x80) // CHECK-NEXT: ] // CHECK-NEXT: Address // CHECK-NEXT: Offset: @@ -64,7 +64,7 @@ f3: // CHECK-NEXT: Type: SHT_ARM_EXIDX (0x70000001) // CHECK-NEXT: Flags [ (0x82) // CHECK-NEXT: SHF_ALLOC (0x2) -// CHECK-NEXT: SHF_LINK_ORDER (0x80) +// CHECK-NEXT: SHF_METADATA (0x80) // CHECK-NEXT: ] // CHECK-NEXT: Address // CHECK-NEXT: Offset: @@ -79,7 +79,7 @@ f3: // CHECK-NEXT: Type: SHT_ARM_EXIDX (0x70000001) // CHECK-NEXT: Flags [ (0x82) // CHECK-NEXT: SHF_ALLOC (0x2) -// CHECK-NEXT: SHF_LINK_ORDER (0x80) +// CHECK-NEXT: SHF_METADATA (0x80) // CHECK-NEXT: ] // CHECK-NEXT: Address // CHECK-NEXT: Offset: @@ -94,7 +94,7 @@ f3: // CHECK-NEXT: Type: SHT_ARM_EXIDX (0x70000001) // CHECK-NEXT: Flags [ (0x82) // CHECK-NEXT: SHF_ALLOC (0x2) -// CHECK-NEXT: SHF_LINK_ORDER (0x80) +// CHECK-NEXT: SHF_METADATA (0x80) // CHECK-NEXT: ] // CHECK-NEXT: Address // CHECK-NEXT: Offset: @@ -109,7 +109,7 @@ f3: // CHECK-NEXT: Type: SHT_ARM_EXIDX (0x70000001) // CHECK-NEXT: Flags [ (0x82) // CHECK-NEXT: SHF_ALLOC (0x2) -// CHECK-NEXT: SHF_LINK_ORDER (0x80) +// CHECK-NEXT: SHF_METADATA (0x80) // CHECK-NEXT: ] // CHECK-NEXT: Address // CHECK-NEXT: Offset: @@ -124,7 +124,7 @@ f3: // CHECK-NEXT: Type: SHT_ARM_EXIDX (0x70000001) // CHECK-NEXT: Flags [ (0x82) // CHECK-NEXT: SHF_ALLOC (0x2) -// CHECK-NEXT: SHF_LINK_ORDER (0x80) +// CHECK-NEXT: SHF_METADATA (0x80) // CHECK-NEXT: ] // CHECK-NEXT: Address // CHECK-NEXT: Offset: diff --git a/lld/test/ELF/arm-use-r-output.s b/lld/test/ELF/arm-use-r-output.s index 9183624..78147b9 100644 --- a/lld/test/ELF/arm-use-r-output.s +++ b/lld/test/ELF/arm-use-r-output.s @@ -4,7 +4,7 @@ // RUN: ld.lld -shared %t2.o -o %t.so // We used to crash using the output of -r because of the relative order of -// SHF_LINK_ORDER sections. +// SHF_METADATA sections. // That can be fixed by changing -r or making the regular link more flexible, // so this is an end to end test. diff --git a/lld/test/ELF/gc-sections-metadata.s b/lld/test/ELF/gc-sections-metadata.s new file mode 100644 index 0000000..d24844a8 --- /dev/null +++ b/lld/test/ELF/gc-sections-metadata.s @@ -0,0 +1,36 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o +# RUN: ld.lld --gc-sections %t.o -o %t +# RUN: llvm-objdump -section-headers %t | FileCheck %s + +# CHECK: 1 .foo1 +# CHECK-NEXT: .bar1 +# CHECK-NEXT: .zed1 +# CHECK-NEXT: .text +# CHECK-NEXT: .comment +# CHECK-NEXT: .symtab +# CHECK-NEXT: .shstrtab +# CHECK-NEXT: .strtab + +.global _start +_start: +.quad .foo1 + +.section .foo1,"a" +.quad 0 + +.section .foo2,"a" +.quad 0 + +.section .bar1,"am",@progbits,.foo1 +.quad .zed1 + +.section .bar2,"am",@progbits,.foo2 +.quad .zed2 + +.section .zed1,"a" +.quad 0 + +.section .zed2,"a" +.quad 0 diff --git a/llvm/include/llvm/MC/MCContext.h b/llvm/include/llvm/MC/MCContext.h index 5c6c179..733be90 100644 --- a/llvm/include/llvm/MC/MCContext.h +++ b/llvm/include/llvm/MC/MCContext.h @@ -352,7 +352,15 @@ namespace llvm { MCSectionELF *getELFSection(const Twine &Section, unsigned Type, unsigned Flags, unsigned EntrySize, - const Twine &Group, unsigned UniqueID); + const Twine &Group, unsigned UniqueID) { + return getELFSection(Section, Type, Flags, EntrySize, Group, UniqueID, + nullptr); + } + + MCSectionELF *getELFSection(const Twine &Section, unsigned Type, + unsigned Flags, unsigned EntrySize, + const Twine &Group, unsigned UniqueID, + const MCSectionELF *Associated); MCSectionELF *getELFSection(const Twine &Section, unsigned Type, unsigned Flags, unsigned EntrySize, diff --git a/llvm/include/llvm/Support/ELF.h b/llvm/include/llvm/Support/ELF.h index 9bbec86..6076d9f 100644 --- a/llvm/include/llvm/Support/ELF.h +++ b/llvm/include/llvm/Support/ELF.h @@ -731,7 +731,7 @@ enum : unsigned { SHF_INFO_LINK = 0x40U, // Adds special ordering requirements for link editors. - SHF_LINK_ORDER = 0x80U, + SHF_METADATA = 0x80U, // This section requires special OS-specific processing to avoid incorrect // behavior. diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp index e9f4f1c..884a5bc 100644 --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -1157,8 +1157,7 @@ void ELFObjectWriter::writeSection(const SectionIndexMapTy &SectionIndexMap, break; } - if (TargetObjectWriter->getEMachine() == ELF::EM_ARM && - Section.getType() == ELF::SHT_ARM_EXIDX) + if (Section.getFlags() & ELF::SHF_METADATA) sh_link = SectionIndexMap.lookup(Section.getAssociatedSection()); WriteSecHdrEntry(StrTabBuilder.getOffset(Section.getSectionName()), diff --git a/llvm/lib/MC/MCContext.cpp b/llvm/lib/MC/MCContext.cpp index 16c2c99..d4bed0a 100644 --- a/llvm/lib/MC/MCContext.cpp +++ b/llvm/lib/MC/MCContext.cpp @@ -358,13 +358,14 @@ MCSectionELF *MCContext::getELFNamedSection(const Twine &Prefix, MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type, unsigned Flags, unsigned EntrySize, - const Twine &Group, unsigned UniqueID) { + const Twine &Group, unsigned UniqueID, + const MCSectionELF *Associated) { MCSymbolELF *GroupSym = nullptr; if (!Group.isTriviallyEmpty() && !Group.str().empty()) GroupSym = cast(getOrCreateSymbol(Group)); return getELFSection(Section, Type, Flags, EntrySize, GroupSym, UniqueID, - nullptr); + Associated); } MCSectionELF *MCContext::getELFSection(const Twine &Section, unsigned Type, diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp index c7b53ec..460d232 100644 --- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp +++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp @@ -145,6 +145,7 @@ private: bool maybeParseSectionType(StringRef &TypeName); bool parseMergeSize(int64_t &Size); bool parseGroup(StringRef &GroupName); + bool parseMetadataSym(MCSectionELF *&Associated); bool maybeParseUniqueID(int64_t &UniqueID); }; @@ -286,6 +287,9 @@ static unsigned parseSectionFlags(StringRef flagsStr, bool *UseLastGroup) { case 'w': flags |= ELF::SHF_WRITE; break; + case 'm': + flags |= ELF::SHF_METADATA; + break; case 'M': flags |= ELF::SHF_MERGE; break; @@ -414,6 +418,21 @@ bool ELFAsmParser::parseGroup(StringRef &GroupName) { return false; } +bool ELFAsmParser::parseMetadataSym(MCSectionELF *&Associated) { + MCAsmLexer &L = getLexer(); + if (L.isNot(AsmToken::Comma)) + return TokError("expected metadata symbol"); + Lex(); + StringRef Name; + if (getParser().parseIdentifier(Name)) + return true; + MCSymbol *Sym = getContext().lookupSymbol(Name); + if (!Sym || !Sym->isInSection()) + return TokError("symbol is not in a section: " + Name); + Associated = cast(&Sym->getSection()); + return false; +} + bool ELFAsmParser::maybeParseUniqueID(int64_t &UniqueID) { MCAsmLexer &L = getLexer(); if (L.isNot(AsmToken::Comma)) @@ -449,6 +468,7 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) { const MCExpr *Subsection = nullptr; bool UseLastGroup = false; StringRef UniqueStr; + MCSectionELF *Associated = nullptr; int64_t UniqueID = ~0; // Set the defaults first. @@ -511,6 +531,9 @@ bool ELFAsmParser::ParseSectionArguments(bool IsPush, SMLoc loc) { if (Group) if (parseGroup(GroupName)) return true; + if (Flags & ELF::SHF_METADATA) + if (parseMetadataSym(Associated)) + return true; if (maybeParseUniqueID(UniqueID)) return true; } @@ -560,8 +583,8 @@ EndStmt: } } - MCSection *ELFSection = getContext().getELFSection(SectionName, Type, Flags, - Size, GroupName, UniqueID); + MCSection *ELFSection = getContext().getELFSection( + SectionName, Type, Flags, Size, GroupName, UniqueID, Associated); getStreamer().SwitchSection(ELFSection, Subsection); if (getContext().getGenDwarfForAssembly()) { diff --git a/llvm/lib/ObjectYAML/ELFYAML.cpp b/llvm/lib/ObjectYAML/ELFYAML.cpp index 3052901..fa06cd1 100644 --- a/llvm/lib/ObjectYAML/ELFYAML.cpp +++ b/llvm/lib/ObjectYAML/ELFYAML.cpp @@ -416,7 +416,7 @@ void ScalarBitSetTraits::bitset(IO &IO, BCase(SHF_MERGE); BCase(SHF_STRINGS); BCase(SHF_INFO_LINK); - BCase(SHF_LINK_ORDER); + BCase(SHF_METADATA); BCase(SHF_OS_NONCONFORMING); BCase(SHF_GROUP); BCase(SHF_TLS); diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp index 043b54b..0ff5fa0 100644 --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp @@ -1155,8 +1155,8 @@ inline void ARMELFStreamer::SwitchToExTabSection(const MCSymbol &FnStart) { inline void ARMELFStreamer::SwitchToExIdxSection(const MCSymbol &FnStart) { SwitchToEHSection(".ARM.exidx", ELF::SHT_ARM_EXIDX, - ELF::SHF_ALLOC | ELF::SHF_LINK_ORDER, - SectionKind::getData(), FnStart); + ELF::SHF_ALLOC | ELF::SHF_METADATA, SectionKind::getData(), + FnStart); } void ARMELFStreamer::EmitFixup(const MCExpr *Expr, MCFixupKind Kind) { diff --git a/llvm/test/MC/ARM/eh-directive-section-comdat.s b/llvm/test/MC/ARM/eh-directive-section-comdat.s index 8b7f32e..a4b9d00 100644 --- a/llvm/test/MC/ARM/eh-directive-section-comdat.s +++ b/llvm/test/MC/ARM/eh-directive-section-comdat.s @@ -111,7 +111,7 @@ func1: @ CHECK: Flags [ (0x282) @ CHECK: SHF_ALLOC (0x2) @ CHECK: SHF_GROUP (0x200) -@ CHECK: SHF_LINK_ORDER (0x80) +@ CHECK: SHF_METADATA (0x80) @ CHECK: ] @ CHECK: Link: 4 @ CHECK: } diff --git a/llvm/test/MC/ARM/eh-directive-text-section.s b/llvm/test/MC/ARM/eh-directive-text-section.s index 10ccdd5..1de4f88 100644 --- a/llvm/test/MC/ARM/eh-directive-text-section.s +++ b/llvm/test/MC/ARM/eh-directive-text-section.s @@ -51,7 +51,7 @@ func1: @ CHECK: Type: SHT_ARM_EXIDX (0x70000001) @ CHECK: Flags [ (0x82) @ CHECK: SHF_ALLOC (0x2) -@ CHECK: SHF_LINK_ORDER (0x80) +@ CHECK: SHF_METADATA (0x80) @ CHECK: ] @------------------------------------------------------------------------------- diff --git a/llvm/test/MC/ARM/eh-link.s b/llvm/test/MC/ARM/eh-link.s index 19fe14d..9e7a1e7 100644 --- a/llvm/test/MC/ARM/eh-link.s +++ b/llvm/test/MC/ARM/eh-link.s @@ -31,7 +31,7 @@ @ CHECK-NEXT: Flags [ @ CHECK-NEXT: SHF_ALLOC @ CHECK-NEXT: SHF_GROUP -@ CHECK-NEXT: SHF_LINK_ORDER +@ CHECK-NEXT: SHF_METADATA @ CHECK-NEXT: ] @ CHECK-NEXT: Address: 0x0 @ CHECK-NEXT: Offset: @@ -66,7 +66,7 @@ @ CHECK-NEXT: Flags [ @ CHECK-NEXT: SHF_ALLOC @ CHECK-NEXT: SHF_GROUP -@ CHECK-NEXT: SHF_LINK_ORDER +@ CHECK-NEXT: SHF_METADATA @ CHECK-NEXT: ] @ CHECK-NEXT: Address: 0x0 @ CHECK-NEXT: Offset: diff --git a/llvm/test/MC/ELF/section-metadata-err1.s b/llvm/test/MC/ELF/section-metadata-err1.s new file mode 100644 index 0000000..eb468f6 --- /dev/null +++ b/llvm/test/MC/ELF/section-metadata-err1.s @@ -0,0 +1,5 @@ +// RUN: not llvm-mc -triple x86_64-pc-linux-gnu %s -o - 2>&1 | FileCheck %s + +// CHECK: error: symbol is not in a section: foo + + .section .shf_metadata,"am",@progbits,foo diff --git a/llvm/test/MC/ELF/section-metadata-err2.s b/llvm/test/MC/ELF/section-metadata-err2.s new file mode 100644 index 0000000..032e000 --- /dev/null +++ b/llvm/test/MC/ELF/section-metadata-err2.s @@ -0,0 +1,6 @@ +// RUN: not llvm-mc -triple x86_64-pc-linux-gnu %s -o - 2>&1 | FileCheck %s + +// CHECK: error: symbol is not in a section: foo + + .quad foo + .section .shf_metadata,"am",@progbits,foo diff --git a/llvm/test/MC/ELF/section-metadata-err3.s b/llvm/test/MC/ELF/section-metadata-err3.s new file mode 100644 index 0000000..4d8d0e2 --- /dev/null +++ b/llvm/test/MC/ELF/section-metadata-err3.s @@ -0,0 +1,6 @@ +// RUN: not llvm-mc -triple x86_64-pc-linux-gnu %s -o - 2>&1 | FileCheck %s + +// CHECK: error: symbol is not in a section: foo + + foo = 42 + .section .shf_metadata,"am",@progbits,foo diff --git a/llvm/test/MC/ELF/section-metadata-err4.s b/llvm/test/MC/ELF/section-metadata-err4.s new file mode 100644 index 0000000..3c843c0 --- /dev/null +++ b/llvm/test/MC/ELF/section-metadata-err4.s @@ -0,0 +1,5 @@ +// RUN: not llvm-mc -triple x86_64-pc-linux-gnu %s -o - 2>&1 | FileCheck %s + +// CHECK: error: expected metadata symbol + + .section .shf_metadata,"am",@progbits diff --git a/llvm/test/MC/ELF/section.s b/llvm/test/MC/ELF/section.s index 0277be5..b588222 100644 --- a/llvm/test/MC/ELF/section.s +++ b/llvm/test/MC/ELF/section.s @@ -149,3 +149,69 @@ bar: // CHECK: Name: bar-"foo" // CHECK: Section { // CHECK: Name: foo + +// Test SHF_METADATA + +.section .shf_metadata_target1, "a" + .quad 0 +.section .shf_metadata_target2, "a", @progbits, unique, 1 +.Lshf_metadata_target2_1: + .quad 0 +.section .shf_metadata_target2, "a", @progbits, unique, 2 +.Lshf_metadata_target2_2: + .quad 0 + +.section .shf_metadata1,"am",@progbits,.Lshf_metadata_target2_1 +.section .shf_metadata2,"am",@progbits,.Lshf_metadata_target2_2 +.section .shf_metadata3,"am",@progbits,.shf_metadata_target1 + +// CHECK: Section { +// CHECK: Index: 22 +// CHECK-NEXT: Name: .shf_metadata_target1 + +// CHECK: Section { +// CHECK: Index: 23 +// CHECK-NEXT: Name: .shf_metadata_target2 + +// CHECK: Section { +// CHECK: Index: 24 +// CHECK-NEXT: Name: .shf_metadata_target2 + +// CHECK: Section { +// CHECK: Name: .shf_metadata1 +// CHECK-NEXT: Type: SHT_PROGBITS +// CHECK-NEXT: Flags [ +// CHECK-NEXT: SHF_ALLOC +// CHECK-NEXT: SHF_METADATA +// CHECK-NEXT: ] +// CHECK-NEXT: Address: +// CHECK-NEXT: Offset: +// CHECK-NEXT: Size: +// CHECK-NEXT: Link: 23 +// CHECK-NEXT: Info: 0 + +// CHECK: Section { +// CHECK: Name: .shf_metadata2 +// CHECK-NEXT: Type: SHT_PROGBITS +// CHECK-NEXT: Flags [ +// CHECK-NEXT: SHF_ALLOC +// CHECK-NEXT: SHF_METADATA +// CHECK-NEXT: ] +// CHECK-NEXT: Address: +// CHECK-NEXT: Offset: +// CHECK-NEXT: Size: +// CHECK-NEXT: Link: 24 +// CHECK-NEXT: Info: 0 + +// CHECK: Section { +// CHECK: Name: .shf_metadata3 +// CHECK-NEXT: Type: SHT_PROGBITS +// CHECK-NEXT: Flags [ +// CHECK-NEXT: SHF_ALLOC +// CHECK-NEXT: SHF_METADATA +// CHECK-NEXT: ] +// CHECK-NEXT: Address: +// CHECK-NEXT: Offset: +// CHECK-NEXT: Size: +// CHECK-NEXT: Link: 22 +// CHECK-NEXT: Info: 0 diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index 109dde1..91aff66 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -1041,20 +1041,20 @@ static const char *getGroupType(uint32_t Flag) { } static const EnumEntry ElfSectionFlags[] = { - ENUM_ENT(SHF_WRITE, "W"), - ENUM_ENT(SHF_ALLOC, "A"), - ENUM_ENT(SHF_EXCLUDE, "E"), - ENUM_ENT(SHF_EXECINSTR, "X"), - ENUM_ENT(SHF_MERGE, "M"), - ENUM_ENT(SHF_STRINGS, "S"), - ENUM_ENT(SHF_INFO_LINK, "I"), - ENUM_ENT(SHF_LINK_ORDER, "L"), - ENUM_ENT(SHF_OS_NONCONFORMING, "o"), - ENUM_ENT(SHF_GROUP, "G"), - ENUM_ENT(SHF_TLS, "T"), - ENUM_ENT(SHF_MASKOS, "o"), - ENUM_ENT(SHF_MASKPROC, "p"), - ENUM_ENT_1(SHF_COMPRESSED), + ENUM_ENT(SHF_WRITE, "W"), + ENUM_ENT(SHF_ALLOC, "A"), + ENUM_ENT(SHF_EXCLUDE, "E"), + ENUM_ENT(SHF_EXECINSTR, "X"), + ENUM_ENT(SHF_MERGE, "M"), + ENUM_ENT(SHF_STRINGS, "S"), + ENUM_ENT(SHF_INFO_LINK, "I"), + ENUM_ENT(SHF_METADATA, "L"), + ENUM_ENT(SHF_OS_NONCONFORMING, "o"), + ENUM_ENT(SHF_GROUP, "G"), + ENUM_ENT(SHF_TLS, "T"), + ENUM_ENT(SHF_MASKOS, "o"), + ENUM_ENT(SHF_MASKPROC, "p"), + ENUM_ENT_1(SHF_COMPRESSED), }; static const EnumEntry ElfXCoreSectionFlags[] = { @@ -1104,7 +1104,7 @@ static std::string getGNUFlags(uint64_t Flags) { case ELF::SHF_MERGE: case ELF::SHF_STRINGS: case ELF::SHF_INFO_LINK: - case ELF::SHF_LINK_ORDER: + case ELF::SHF_METADATA: case ELF::SHF_OS_NONCONFORMING: case ELF::SHF_GROUP: case ELF::SHF_TLS: