Skip to content

Commit 1c198b3

Browse files
nikictstellar
authored andcommitted
Revert [MC][ELF] Emit separate unique sections for different flags
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
1 parent 4728892 commit 1c198b3

File tree

6 files changed

+68
-213
lines changed

6 files changed

+68
-213
lines changed

llvm/include/llvm/MC/MCContext.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -374,17 +374,17 @@ namespace llvm {
374374
bool operator<(const ELFEntrySizeKey &Other) const {
375375
if (SectionName != Other.SectionName)
376376
return SectionName < Other.SectionName;
377-
if (Flags != Other.Flags)
378-
return Flags < Other.Flags;
377+
if ((Flags & ELF::SHF_STRINGS) != (Other.Flags & ELF::SHF_STRINGS))
378+
return Other.Flags & ELF::SHF_STRINGS;
379379
return EntrySize < Other.EntrySize;
380380
}
381381
};
382382

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

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

593593
bool isELFGenericMergeableSection(StringRef Name);
594594

595-
/// Return the unique ID of the section with the given name, flags and entry
596-
/// size, if it exists.
597595
Optional<unsigned> getELFUniqueIDForEntsize(StringRef SectionName,
598596
unsigned Flags,
599597
unsigned EntrySize);

llvm/lib/MC/MCContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ void MCContext::recordELFMergeableSectionInfo(StringRef SectionName,
586586
unsigned Flags, unsigned UniqueID,
587587
unsigned EntrySize) {
588588
bool IsMergeable = Flags & ELF::SHF_MERGE;
589-
if (UniqueID == GenericSectionID)
589+
if (IsMergeable && (UniqueID == GenericSectionID))
590590
ELFSeenGenericMergeableSections.insert(SectionName);
591591

592592
// For mergeable sections or non-mergeable sections with a generic mergeable

llvm/test/CodeGen/Mips/gpopt-explict-section.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
; small data section. Also test that explicitly placing something in the small
88
; data section uses %gp_rel addressing mode.
99

10-
@a = constant [2 x i32] zeroinitializer, section ".rodata", align 4
10+
@a = global [2 x i32] zeroinitializer, section ".rodata", align 4
1111
@b = global [4 x i32] zeroinitializer, section ".sdata", align 4
1212
@c = global [4 x i32] zeroinitializer, section ".sbss", align 4
1313

llvm/test/CodeGen/X86/elf-unique-sections-by-flags.ll

Lines changed: 0 additions & 140 deletions
This file was deleted.

0 commit comments

Comments
 (0)