Skip to content

Commit

Permalink
Revert [MC][ELF] Emit separate unique sections for different flags
Browse files Browse the repository at this point in the history
Commit Message from @MaskRay:

Rust has a fragile embed-bitcode implementation
(https://github.com/rust-lang/rust/blob/bddb59cf07efcf6e606f16b87f85e3ecd2c1ca69/compiler/rustc_codegen_llvm/src/back/write.rs#L970-L1017)
which relied on the previous LLVM MC behavior.  Rust's LLVM fork
has carried a revert. This commit made the similar revert to help
distributions since they would otherwise probably carry a similar patch
(as they ship rust linked against system LLVM).

Fixes https://bugs.llvm.org/show_bug.cgi?id=51207.

Differential Revision: https://reviews.llvm.org/D107216
  • Loading branch information
nikic authored and tstellar committed Sep 10, 2021
1 parent a967752 commit b6614b2
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 213 deletions.
16 changes: 7 additions & 9 deletions include/llvm/MC/MCContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,17 +374,17 @@ namespace llvm {
bool operator<(const ELFEntrySizeKey &Other) const {
if (SectionName != Other.SectionName)
return SectionName < Other.SectionName;
if (Flags != Other.Flags)
return Flags < Other.Flags;
if ((Flags & ELF::SHF_STRINGS) != (Other.Flags & ELF::SHF_STRINGS))
return Other.Flags & ELF::SHF_STRINGS;
return EntrySize < Other.EntrySize;
}
};

// Symbols must be assigned to a section with a compatible entry size and
// flags. This map is used to assign unique IDs to sections to distinguish
// between sections with identical names but incompatible entry sizes and/or
// flags. This can occur when a symbol is explicitly assigned to a section,
// e.g. via __attribute__((section("myname"))).
// Symbols must be assigned to a section with a compatible entry
// size. This map is used to assign unique IDs to sections to
// distinguish between sections with identical names but incompatible entry
// sizes. This can occur when a symbol is explicitly assigned to a
// section, e.g. via __attribute__((section("myname"))).
std::map<ELFEntrySizeKey, unsigned> ELFEntrySizeMap;

// This set is used to record the generic mergeable section names seen.
Expand Down Expand Up @@ -592,8 +592,6 @@ namespace llvm {

bool isELFGenericMergeableSection(StringRef Name);

/// Return the unique ID of the section with the given name, flags and entry
/// size, if it exists.
Optional<unsigned> getELFUniqueIDForEntsize(StringRef SectionName,
unsigned Flags,
unsigned EntrySize);
Expand Down
2 changes: 1 addition & 1 deletion lib/MC/MCContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ void MCContext::recordELFMergeableSectionInfo(StringRef SectionName,
unsigned Flags, unsigned UniqueID,
unsigned EntrySize) {
bool IsMergeable = Flags & ELF::SHF_MERGE;
if (UniqueID == GenericSectionID)
if (IsMergeable && (UniqueID == GenericSectionID))
ELFSeenGenericMergeableSections.insert(SectionName);

// For mergeable sections or non-mergeable sections with a generic mergeable
Expand Down
2 changes: 1 addition & 1 deletion test/CodeGen/Mips/gpopt-explict-section.ll
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
; small data section. Also test that explicitly placing something in the small
; data section uses %gp_rel addressing mode.

@a = constant [2 x i32] zeroinitializer, section ".rodata", align 4
@a = global [2 x i32] zeroinitializer, section ".rodata", align 4
@b = global [4 x i32] zeroinitializer, section ".sdata", align 4
@c = global [4 x i32] zeroinitializer, section ".sbss", align 4

Expand Down
140 changes: 0 additions & 140 deletions test/CodeGen/X86/elf-unique-sections-by-flags.ll

This file was deleted.

Loading

0 comments on commit b6614b2

Please sign in to comment.