[llvm] r234142 - Store the sh_link of ARM_EXIDX directly in MCSectionELF.
Rafael Espindola
rafael.espindola at gmail.com
Sun Apr 5 21:25:18 PDT 2015
Author: rafael
Date: Sun Apr 5 23:25:18 2015
New Revision: 234142
URL: http://llvm.org/viewvc/llvm-project?rev=234142&view=rev
Log:
Store the sh_link of ARM_EXIDX directly in MCSectionELF.
This avoids some pretty horrible and broken name based section handling.
Added:
llvm/trunk/test/MC/ARM/eh-link.s
Modified:
llvm/trunk/include/llvm/MC/MCContext.h
llvm/trunk/lib/MC/ELFObjectWriter.cpp
llvm/trunk/lib/MC/MCContext.cpp
llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
Modified: llvm/trunk/include/llvm/MC/MCContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=234142&r1=234141&r2=234142&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h (original)
+++ llvm/trunk/include/llvm/MC/MCContext.h Sun Apr 5 23:25:18 2015
@@ -334,6 +334,12 @@ namespace llvm {
StringRef Group, unsigned UniqueID,
const char *BeginSymName);
+ const MCSectionELF *getELFSection(StringRef Section, unsigned Type,
+ unsigned Flags, unsigned EntrySize,
+ const MCSymbol *Group, unsigned UniqueID,
+ const char *BeginSymName,
+ const MCSectionELF *Associated);
+
const MCSectionELF *createELFRelSection(StringRef Name, unsigned Type,
unsigned Flags, unsigned EntrySize,
const MCSymbol *Group,
Modified: llvm/trunk/lib/MC/ELFObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/ELFObjectWriter.cpp?rev=234142&r1=234141&r2=234142&view=diff
==============================================================================
--- llvm/trunk/lib/MC/ELFObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/ELFObjectWriter.cpp Sun Apr 5 23:25:18 2015
@@ -1546,19 +1546,8 @@ void ELFObjectWriter::writeSection(MCAss
}
if (TargetObjectWriter->getEMachine() == ELF::EM_ARM &&
- Section.getType() == ELF::SHT_ARM_EXIDX) {
- StringRef SecName(Section.getSectionName());
- if (SecName == ".ARM.exidx") {
- sh_link = SectionIndexMap.lookup(Asm.getContext().getELFSection(
- ".text", ELF::SHT_PROGBITS, ELF::SHF_EXECINSTR | ELF::SHF_ALLOC));
- } else if (SecName.startswith(".ARM.exidx")) {
- StringRef GroupName =
- Section.getGroup() ? Section.getGroup()->getName() : "";
- sh_link = SectionIndexMap.lookup(Asm.getContext().getELFSection(
- SecName.substr(sizeof(".ARM.exidx") - 1), ELF::SHT_PROGBITS,
- ELF::SHF_EXECINSTR | ELF::SHF_ALLOC, 0, GroupName));
- }
- }
+ Section.getType() == ELF::SHT_ARM_EXIDX)
+ sh_link = SectionIndexMap.lookup(Section.getAssociatedSection());
WriteSecHdrEntry(ShStrTabBuilder.getOffset(Section.getSectionName()),
Section.getType(),
Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=234142&r1=234141&r2=234142&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Sun Apr 5 23:25:18 2015
@@ -295,11 +295,22 @@ const MCSectionELF *MCContext::getELFSec
StringRef Group, unsigned UniqueID,
const char *BeginSymName) {
MCSymbol *GroupSym = nullptr;
- if (!Group.empty()) {
+ if (!Group.empty())
GroupSym = GetOrCreateSymbol(Group);
- Group = GroupSym->getName();
- }
+ return getELFSection(Section, Type, Flags, EntrySize, GroupSym, UniqueID,
+ BeginSymName, nullptr);
+}
+
+const MCSectionELF *MCContext::getELFSection(StringRef Section, unsigned Type,
+ unsigned Flags, unsigned EntrySize,
+ const MCSymbol *GroupSym,
+ unsigned UniqueID,
+ const char *BeginSymName,
+ const MCSectionELF *Associated) {
+ StringRef Group = "";
+ if (GroupSym)
+ Group = GroupSym->getName();
// Do the lookup, if we have a hit, return it.
auto IterBool = ELFUniquingMap.insert(
std::make_pair(ELFSectionKey{Section, Group, UniqueID}, nullptr));
@@ -321,7 +332,7 @@ const MCSectionELF *MCContext::getELFSec
MCSectionELF *Result =
new (*this) MCSectionELF(CachedName, Type, Flags, Kind, EntrySize,
- GroupSym, UniqueID, Begin, nullptr);
+ GroupSym, UniqueID, Begin, Associated);
Entry.second = Result;
return Result;
}
Modified: llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp?rev=234142&r1=234141&r2=234142&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp (original)
+++ llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp Sun Apr 5 23:25:18 2015
@@ -1083,14 +1083,13 @@ inline void ARMELFStreamer::SwitchToEHSe
}
// Get .ARM.extab or .ARM.exidx section
- const MCSectionELF *EHSection = nullptr;
- if (const MCSymbol *Group = FnSection.getGroup()) {
- EHSection =
- getContext().getELFSection(EHSecName, Type, Flags | ELF::SHF_GROUP,
- FnSection.getEntrySize(), Group->getName());
- } else {
- EHSection = getContext().getELFSection(EHSecName, Type, Flags);
- }
+ const MCSymbol *Group = FnSection.getGroup();
+ if (Group)
+ Flags |= ELF::SHF_GROUP;
+ const MCSectionELF *EHSection =
+ getContext().getELFSection(EHSecName, Type, Flags, 0, Group,
+ FnSection.getUniqueID(), nullptr, &FnSection);
+
assert(EHSection && "Failed to get the required EH section");
// Switch to .ARM.extab or .ARM.exidx section
Added: llvm/trunk/test/MC/ARM/eh-link.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ARM/eh-link.s?rev=234142&view=auto
==============================================================================
--- llvm/trunk/test/MC/ARM/eh-link.s (added)
+++ llvm/trunk/test/MC/ARM/eh-link.s Sun Apr 5 23:25:18 2015
@@ -0,0 +1,90 @@
+@ RUN: llvm-mc %s -triple=armv7-unknown-linux-gnueabi -filetype=obj -o - \
+@ RUN: | llvm-readobj -s | FileCheck %s
+
+@ Test that the ARM_EXIDX sections point (Link) to the corresponding text
+@ sections.
+
+@ FIXME: The section numbers are not important. If llvm-readobj printed the
+@ name first we could use a FileCheck variable.
+
+@ CHECK: Section {
+@ CHECK: Index: 6
+@ CHECK-NEXT: Name: .text
+@ CHECK-NEXT: Type: SHT_PROGBITS
+@ CHECK-NEXT: Flags [
+@ CHECK-NEXT: SHF_ALLOC
+@ CHECK-NEXT: SHF_EXECINSTR
+@ CHECK-NEXT: SHF_GROUP
+@ CHECK-NEXT: ]
+@ CHECK-NEXT: Address: 0x0
+@ CHECK-NEXT: Offset: 0x54
+@ CHECK-NEXT: Size: 4
+@ CHECK-NEXT: Link: 0
+@ CHECK-NEXT: Info: 0
+@ CHECK-NEXT: AddressAlignment: 1
+@ CHECK-NEXT: EntrySize: 0
+@ CHECK-NEXT: }
+@ CHECK-NEXT: Section {
+@ CHECK-NEXT: Index: 7
+@ CHECK-NEXT: Name: .ARM.exidx
+@ CHECK-NEXT: Type: SHT_ARM_EXIDX
+@ CHECK-NEXT: Flags [
+@ CHECK-NEXT: SHF_ALLOC
+@ CHECK-NEXT: SHF_GROUP
+@ CHECK-NEXT: SHF_LINK_ORDER
+@ CHECK-NEXT: ]
+@ CHECK-NEXT: Address: 0x0
+@ CHECK-NEXT: Offset: 0x58
+@ CHECK-NEXT: Size: 8
+@ CHECK-NEXT: Link: 6
+@ CHECK-NEXT: Info: 0
+@ CHECK-NEXT: AddressAlignment: 4
+@ CHECK-NEXT: EntrySize: 0
+@ CHECK-NEXT: }
+
+@ CHECK: Section {
+@ CHECK: Index: 9
+@ CHECK-NEXT: Name: .text
+@ CHECK-NEXT: Type: SHT_PROGBITS
+@ CHECK-NEXT: Flags [
+@ CHECK-NEXT: SHF_ALLOC
+@ CHECK-NEXT: SHF_EXECINSTR
+@ CHECK-NEXT: SHF_GROUP
+@ CHECK-NEXT: ]
+@ CHECK-NEXT: Address: 0x0
+@ CHECK-NEXT: Offset: 0x60
+@ CHECK-NEXT: Size: 4
+@ CHECK-NEXT: Link: 0
+@ CHECK-NEXT: Info: 0
+@ CHECK-NEXT: AddressAlignment: 1
+@ CHECK-NEXT: EntrySize: 0
+@ CHECK-NEXT: }
+@ CHECK-NEXT: Section {
+@ CHECK-NEXT: Index: 10
+@ CHECK-NEXT: Name: .ARM.exidx
+@ CHECK-NEXT: Type: SHT_ARM_EXIDX
+@ CHECK-NEXT: Flags [
+@ CHECK-NEXT: SHF_ALLOC
+@ CHECK-NEXT: SHF_GROUP
+@ CHECK-NEXT: SHF_LINK_ORDER
+@ CHECK-NEXT: ]
+@ CHECK-NEXT: Address: 0x0
+@ CHECK-NEXT: Offset: 0x64
+@ CHECK-NEXT: Size: 8
+@ CHECK-NEXT: Link: 9
+@ CHECK-NEXT: Info: 0
+@ CHECK-NEXT: AddressAlignment: 4
+@ CHECK-NEXT: EntrySize: 0
+@ CHECK-NEXT: }
+
+ .section .text,"axG",%progbits,f,comdat
+f:
+ .fnstart
+ mov pc, lr
+ .fnend
+
+ .section .text,"axG",%progbits,g,comdat
+g:
+ .fnstart
+ mov pc, lr
+ .fnend
More information about the llvm-commits
mailing list