[lld] b6c8cba - [ELF] Move ++nextGroupId from InputFile ctor to callers. NFC (#191685)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 11 22:25:50 PDT 2026
Author: Fangrui Song
Date: 2026-04-11T22:25:45-07:00
New Revision: b6c8cba516daabced0105114a7bcc745bc52faae
URL: https://github.com/llvm/llvm-project/commit/b6c8cba516daabced0105114a7bcc745bc52faae
DIFF: https://github.com/llvm/llvm-project/commit/b6c8cba516daabced0105114a7bcc745bc52faae.diff
LOG: [ELF] Move ++nextGroupId from InputFile ctor to callers. NFC (#191685)
Move this side effect to the call sites in addFile() where the groupId
assignment is more visible.
This makes InputFile construction safe to call from parallel contexts.
Added:
Modified:
lld/ELF/Driver.cpp
lld/ELF/InputFiles.cpp
Removed:
################################################################################
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 09aa6af5ee2c7..24718d2d2186a 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -254,6 +254,8 @@ void LinkerDriver::addFile(StringRef path, bool withLOption) {
if (ctx.arg.formatBinary) {
files.push_back(std::make_unique<BinaryFile>(ctx, mbref));
+ if (!isInGroup)
+ ++nextGroupId;
return;
}
@@ -321,7 +323,7 @@ void LinkerDriver::addFile(StringRef path, bool withLOption) {
ctx, mbref, withLOption ? path::filename(path) : path);
f->init();
files.push_back(std::move(f));
- return;
+ break;
}
case file_magic::bitcode:
files.push_back(std::make_unique<BitcodeFile>(ctx, mbref, "", 0, inLib));
@@ -332,7 +334,12 @@ void LinkerDriver::addFile(StringRef path, bool withLOption) {
break;
default:
ErrAlways(ctx) << path << ": unknown file type";
+ return;
}
+ // All files within the same --{start,end}-group get the same group ID.
+ // Otherwise, a new file will get a new group ID.
+ if (!isInGroup)
+ ++nextGroupId;
}
// Add a given library by searching it from input search paths.
diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index f774391c821c9..c2737ea57d0f6 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -207,12 +207,7 @@ static void updateSupportedARMFeatures(Ctx &ctx,
}
InputFile::InputFile(Ctx &ctx, Kind k, MemoryBufferRef m)
- : ctx(ctx), mb(m), groupId(ctx.driver.nextGroupId), fileKind(k) {
- // All files within the same --{start,end}-group get the same group ID.
- // Otherwise, a new file will get a new group ID.
- if (!ctx.driver.isInGroup)
- ++ctx.driver.nextGroupId;
-}
+ : ctx(ctx), mb(m), groupId(ctx.driver.nextGroupId), fileKind(k) {}
InputFile::~InputFile() {}
More information about the llvm-commits
mailing list