Skip to content

Commit 5b51d45

Browse files
authored
[X86] Use ".lrodata" prefix for large mergeable constants (#81900)
Otherwise with a small enough large-data-threshold, we can get .rodata.* sections marked large, making .rodata large in the final binary.
1 parent d2c9a19 commit 5b51d45

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -635,21 +635,22 @@ static SmallString<128>
635635
getELFSectionNameForGlobal(const GlobalObject *GO, SectionKind Kind,
636636
Mangler &Mang, const TargetMachine &TM,
637637
unsigned EntrySize, bool UniqueSectionName) {
638-
SmallString<128> Name;
638+
SmallString<128> Name =
639+
getSectionPrefixForGlobal(Kind, TM.isLargeGlobalValue(GO));
639640
if (Kind.isMergeableCString()) {
640641
// We also need alignment here.
641642
// FIXME: this is getting the alignment of the character, not the
642643
// alignment of the global!
643644
Align Alignment = GO->getParent()->getDataLayout().getPreferredAlign(
644645
cast<GlobalVariable>(GO));
645646

646-
std::string SizeSpec = ".rodata.str" + utostr(EntrySize) + ".";
647-
Name = SizeSpec + utostr(Alignment.value());
647+
Name += ".str";
648+
Name += utostr(EntrySize);
649+
Name += ".";
650+
Name += utostr(Alignment.value());
648651
} else if (Kind.isMergeableConst()) {
649-
Name = ".rodata.cst";
652+
Name += ".cst";
650653
Name += utostr(EntrySize);
651-
} else {
652-
Name = getSectionPrefixForGlobal(Kind, TM.isLargeGlobalValue(GO));
653654
}
654655

655656
bool HasPrefix = false;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; RUN: llc < %s -relocation-model=pic -filetype=obj -code-model=medium -large-data-threshold=0 -o %t
2+
; RUN: llvm-readelf -S %t | FileCheck %s --check-prefix=LARGE
3+
; RUN: llc < %s -relocation-model=pic -filetype=obj -code-model=medium -large-data-threshold=99 -o %t
4+
; RUN: llvm-readelf -S %t | FileCheck %s --check-prefix=SMALL
5+
6+
; LARGE: .lrodata.str4.4 {{.*}} AMSl
7+
; LARGE: .lrodata.cst8 {{.*}} AMl
8+
9+
; SMALL: .rodata.str4.4 {{.*}} AMS
10+
; SMALL: .rodata.cst8 {{.*}} AM
11+
12+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
13+
target triple = "x86_64--linux"
14+
15+
@str = internal unnamed_addr constant [3 x i32] [i32 1, i32 2, i32 0]
16+
@merge = internal unnamed_addr constant i64 2

0 commit comments

Comments
 (0)