[lld] [ELF] Move ++nextGroupId from InputFile ctor to callers. NFC (PR #191685)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 11 22:25:46 PDT 2026
https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/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.
>From 6a3ff2372b82eb86856daa797d55e16bd8826d14 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Sat, 11 Apr 2026 22:17:48 -0700
Subject: [PATCH] [ELF] Move ++nextGroupId from InputFile ctor to callers. NFC
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.
---
lld/ELF/Driver.cpp | 9 ++++++++-
lld/ELF/InputFiles.cpp | 7 +------
2 files changed, 9 insertions(+), 7 deletions(-)
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