Skip to content

Commit f2b0133

Browse files
committed
[ELF] Move static nextGroupId isInGroup to LinkerDriver
1 parent 18ca7ad commit f2b0133

File tree

5 files changed

+24
-28
lines changed

5 files changed

+24
-28
lines changed

lld/ELF/Config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ class LinkerDriver {
175175
std::vector<InputFile *> files;
176176

177177
public:
178+
// See InputFile::groupId.
179+
uint32_t nextGroupId;
180+
bool isInGroup;
178181
InputFile *armCmseImpLib = nullptr;
179182
SmallVector<std::pair<StringRef, unsigned>, 0> archiveFiles;
180183
};

lld/ELF/Driver.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include "llvm/Object/IRObjectFile.h"
5757
#include "llvm/Remarks/HotnessThresholdParser.h"
5858
#include "llvm/Support/CommandLine.h"
59+
#include "llvm/Support/SaveAndRestore.h"
5960
#include "llvm/Support/Compression.h"
6061
#include "llvm/Support/FileSystem.h"
6162
#include "llvm/Support/GlobPattern.h"
@@ -322,8 +323,7 @@ void LinkerDriver::addFile(StringRef path, bool withLOption) {
322323
//
323324
// All files within the archive get the same group ID to allow mutual
324325
// references for --warn-backrefs.
325-
bool saved = InputFile::isInGroup;
326-
InputFile::isInGroup = true;
326+
SaveAndRestore saved(isInGroup, true);
327327
for (const std::pair<MemoryBufferRef, uint64_t> &p : members) {
328328
auto magic = identify_magic(p.first.getBuffer());
329329
if (magic == file_magic::elf_relocatable) {
@@ -335,9 +335,8 @@ void LinkerDriver::addFile(StringRef path, bool withLOption) {
335335
warn(path + ": archive member '" + p.first.getBufferIdentifier() +
336336
"' is neither ET_REL nor LLVM bitcode");
337337
}
338-
InputFile::isInGroup = saved;
339-
if (!saved)
340-
++InputFile::nextGroupId;
338+
if (!saved.get())
339+
++nextGroupId;
341340
return;
342341
}
343342
case file_magic::elf_shared_object: {
@@ -1934,7 +1933,8 @@ void LinkerDriver::createFiles(opt::InputArgList &args) {
19341933

19351934
// Iterate over argv to process input files and positional arguments.
19361935
std::optional<MemoryBufferRef> defaultScript;
1937-
InputFile::isInGroup = false;
1936+
nextGroupId = 0;
1937+
isInGroup = false;
19381938
bool hasInput = false, hasScript = false;
19391939
for (auto *arg : args) {
19401940
switch (arg->getOption().getID()) {
@@ -2004,30 +2004,30 @@ void LinkerDriver::createFiles(opt::InputArgList &args) {
20042004
armCmseImpLib = createObjFile(*mb);
20052005
break;
20062006
case OPT_start_group:
2007-
if (InputFile::isInGroup)
2007+
if (isInGroup)
20082008
error("nested --start-group");
2009-
InputFile::isInGroup = true;
2009+
isInGroup = true;
20102010
break;
20112011
case OPT_end_group:
2012-
if (!InputFile::isInGroup)
2012+
if (!isInGroup)
20132013
error("stray --end-group");
2014-
InputFile::isInGroup = false;
2015-
++InputFile::nextGroupId;
2014+
isInGroup = false;
2015+
++nextGroupId;
20162016
break;
20172017
case OPT_start_lib:
20182018
if (inLib)
20192019
error("nested --start-lib");
2020-
if (InputFile::isInGroup)
2020+
if (isInGroup)
20212021
error("may not nest --start-lib in --start-group");
20222022
inLib = true;
2023-
InputFile::isInGroup = true;
2023+
isInGroup = true;
20242024
break;
20252025
case OPT_end_lib:
20262026
if (!inLib)
20272027
error("stray --end-lib");
20282028
inLib = false;
2029-
InputFile::isInGroup = false;
2030-
++InputFile::nextGroupId;
2029+
isInGroup = false;
2030+
++nextGroupId;
20312031
break;
20322032
case OPT_push_state:
20332033
stack.emplace_back(ctx.arg.asNeeded, ctx.arg.isStatic, inWholeArchive);

lld/ELF/InputFiles.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ extern template void ObjFile<ELF32BE>::importCmseSymbols();
4848
extern template void ObjFile<ELF64LE>::importCmseSymbols();
4949
extern template void ObjFile<ELF64BE>::importCmseSymbols();
5050

51-
bool InputFile::isInGroup;
52-
uint32_t InputFile::nextGroupId;
53-
5451
// Returns "<internal>", "foo.a(bar.o)" or "baz.o".
5552
std::string lld::toString(const InputFile *f) {
5653
static std::mutex mu;
@@ -206,11 +203,11 @@ static void updateSupportedARMFeatures(Ctx &ctx,
206203
}
207204

208205
InputFile::InputFile(Kind k, MemoryBufferRef m)
209-
: mb(m), groupId(nextGroupId), fileKind(k) {
206+
: mb(m), groupId(ctx.driver.nextGroupId), fileKind(k) {
210207
// All files within the same --{start,end}-group get the same group ID.
211208
// Otherwise, a new file will get a new group ID.
212-
if (!isInGroup)
213-
++nextGroupId;
209+
if (!ctx.driver.isInGroup)
210+
++ctx.driver.nextGroupId;
214211
}
215212

216213
std::optional<MemoryBufferRef> elf::readFile(Ctx &ctx, StringRef path) {

lld/ELF/InputFiles.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ class InputFile {
127127
// --{start,end}-lib get the same group ID. Otherwise, each file gets a new
128128
// group ID. For more info, see checkDependency() in SymbolTable.cpp.
129129
uint32_t groupId;
130-
static bool isInGroup;
131-
static uint32_t nextGroupId;
132130

133131
// If this is an architecture-specific file, the following members
134132
// have ELF type (i.e. ELF{32,64}{LE,BE}) and target machine type.

lld/ELF/ScriptParser.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -385,12 +385,10 @@ void ScriptParser::readExtern() {
385385
}
386386

387387
void ScriptParser::readGroup() {
388-
bool orig = InputFile::isInGroup;
389-
InputFile::isInGroup = true;
388+
SaveAndRestore saved(ctx.driver.isInGroup, true);
390389
readInput();
391-
InputFile::isInGroup = orig;
392-
if (!orig)
393-
++InputFile::nextGroupId;
390+
if (!saved.get())
391+
++ctx.driver.nextGroupId;
394392
}
395393

396394
void ScriptParser::readInclude() {

0 commit comments

Comments
 (0)