Skip to content

[X86] Use ".lrodata" prefix for large mergeable constants #81900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,21 +635,22 @@ static SmallString<128>
getELFSectionNameForGlobal(const GlobalObject *GO, SectionKind Kind,
Mangler &Mang, const TargetMachine &TM,
unsigned EntrySize, bool UniqueSectionName) {
SmallString<128> Name;
SmallString<128> Name =
getSectionPrefixForGlobal(Kind, TM.isLargeGlobalValue(GO));
if (Kind.isMergeableCString()) {
// We also need alignment here.
// FIXME: this is getting the alignment of the character, not the
// alignment of the global!
Align Alignment = GO->getParent()->getDataLayout().getPreferredAlign(
cast<GlobalVariable>(GO));

std::string SizeSpec = ".rodata.str" + utostr(EntrySize) + ".";
Name = SizeSpec + utostr(Alignment.value());
Name += ".str";
Name += utostr(EntrySize);
Name += ".";
Name += utostr(Alignment.value());
} else if (Kind.isMergeableConst()) {
Name = ".rodata.cst";
Name += ".cst";
Name += utostr(EntrySize);
} else {
Name = getSectionPrefixForGlobal(Kind, TM.isLargeGlobalValue(GO));
}

bool HasPrefix = false;
Expand Down
16 changes: 16 additions & 0 deletions llvm/test/CodeGen/X86/code-model-elf-merge-sections.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; RUN: llc < %s -relocation-model=pic -filetype=obj -code-model=medium -large-data-threshold=0 -o %t
; RUN: llvm-readelf -S %t | FileCheck %s --check-prefix=LARGE
; RUN: llc < %s -relocation-model=pic -filetype=obj -code-model=medium -large-data-threshold=99 -o %t
; RUN: llvm-readelf -S %t | FileCheck %s --check-prefix=SMALL

; LARGE: .lrodata.str4.4 {{.*}} AMSl
; LARGE: .lrodata.cst8 {{.*}} AMl

; SMALL: .rodata.str4.4 {{.*}} AMS
; SMALL: .rodata.cst8 {{.*}} AM

target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64--linux"

@str = internal unnamed_addr constant [3 x i32] [i32 1, i32 2, i32 0]
@merge = internal unnamed_addr constant i64 2