-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[lld][ELF] Introduce an option to keep data section prefix. #148985
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
base: main
Are you sure you want to change the base?
Changes from 8 commits
24c1c62
6328b71
25c6149
67e44ed
ed70327
17639b1
b66ecee
5dbe4df
28b26f8
a451287
ed99ca5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,13 +103,48 @@ StringRef LinkerScript::getOutputSectionName(const InputSectionBase *s) const { | |
return ".text"; | ||
} | ||
|
||
for (StringRef v : {".data.rel.ro", ".data", ".rodata", | ||
".bss.rel.ro", ".bss", ".ldata", | ||
".lrodata", ".lbss", ".gcc_except_table", | ||
".init_array", ".fini_array", ".tbss", | ||
".tdata", ".ARM.exidx", ".ARM.extab", | ||
".ctors", ".dtors", ".sbss", | ||
".sdata", ".srodata"}) | ||
// When zKeepDataSectionPrefix is true, keep .hot and .unlikely suffixes | ||
// in data sections. | ||
static constexpr StringRef dataSectionPrefixes[] = { | ||
".data.rel.ro", ".data", ".rodata", ".bss.rel.ro", ".bss", | ||
}; | ||
|
||
for (auto [index, v] : llvm::enumerate(dataSectionPrefixes)) { | ||
StringRef secName = s->name; | ||
if (!secName.consume_front(v)) | ||
continue; | ||
if (!secName.empty() && secName[0] != '.') { | ||
|
||
continue; | ||
} | ||
|
||
// The section name starts with 'v', and the remaining string is either | ||
// empty or starts with a '.' character. If keep-data-section-prefix is | ||
// false, map s to output section with name 'v'. | ||
if (!ctx.arg.zKeepDataSectionPrefix) | ||
return v; | ||
// Preserve .hot or .unlikely suffixes in data sections with | ||
// keep-data-section-prefix=true. | ||
if (isSectionPrefix(".hot", secName)) | ||
return s->name.substr(0, v.size() + 4); | ||
if (isSectionPrefix(".unlikely", secName)) | ||
return s->name.substr(0, v.size() + 9); | ||
if (index == 2) { | ||
|
||
// Place input .rodata.str<N>.hot. or .rodata.cst<N>.hot. into the | ||
// .rodata.hot section. | ||
if (s->name.ends_with(".hot.")) | ||
return ".rodata.hot"; | ||
// Place input .rodata.str<N>.hot. or .rodata.cst<N>.unlikely. into the | ||
// .rodata.unlikely section. | ||
if (s->name.ends_with(".unlikely.")) | ||
return ".rodata.unlikely"; | ||
} | ||
return v; | ||
} | ||
|
||
for (StringRef v : | ||
{".ldata", ".lrodata", ".lbss", ".gcc_except_table", ".init_array", | ||
".fini_array", ".tbss", ".tdata", ".ARM.exidx", ".ARM.extab", ".ctors", | ||
".dtors", ".sbss", ".sdata", ".srodata"}) | ||
if (isSectionPrefix(v, s->name)) | ||
return v; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the recent LLVM change that uses
.data.rel.ro.hot.
(the.
afterhot
is mandatory), can this be simplified?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two ifs before
if (!ctx.arg.zKeepDataSectionPrefix)
applies on the general cases, and there may not be a trailing dot to data sections. For instance, https://gcc.godbolt.org/z/G77P8n6qf compiles a simple source code with-O2 -ffunction-sections -fdata-sections
, and var section name is.section .bss.var
(without trailing dot).