Skip to content

Commit b549db3

Browse files
committed
Simplify complicated logic in BitcodeFile constructor
1 parent 5ea21c5 commit b549db3

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

lld/ELF/InputFiles.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,7 +1759,10 @@ static uint8_t getOsAbi(const Triple &t) {
17591759
// Returns true if adjusted; false otherwise. Non-thin archives are unsupported.
17601760
static bool dtltoAdjustMemberPathIfThinArchive(Ctx &ctx, StringRef archivePath,
17611761
std::string &memberPath) {
1762-
assert(!archivePath.empty() && !ctx.arg.dtltoDistributor.empty());
1762+
assert(!archivePath.empty());
1763+
1764+
if (ctx.arg.dtltoDistributor.empty())
1765+
return false;
17631766

17641767
// Read the archive header to determine if it's a thin archive.
17651768
auto bufferOrErr =
@@ -1794,20 +1797,22 @@ BitcodeFile::BitcodeFile(Ctx &ctx, MemoryBufferRef mb, StringRef archiveName,
17941797
if (ctx.arg.thinLTOIndexOnly)
17951798
path = replaceThinLTOSuffix(ctx, mb.getBufferIdentifier());
17961799

1797-
// ThinLTO assumes that all MemoryBufferRefs given to it have a unique
1798-
// name. If two archives define two members with the same name, this
1799-
// causes a collision which result in only one of the objects being taken
1800-
// into consideration at LTO time (which very likely causes undefined
1801-
// symbols later in the link stage). So we append file offset to make
1802-
// filename unique.
18031800
StringSaver &ss = ctx.saver;
1804-
StringRef name =
1805-
(archiveName.empty() ||
1806-
(!ctx.arg.dtltoDistributor.empty() &&
1807-
dtltoAdjustMemberPathIfThinArchive(ctx, archiveName, path)))
1808-
? ss.save(path)
1809-
: ss.save(archiveName + "(" + path::filename(path) + " at " +
1810-
utostr(offsetInArchive) + ")");
1801+
StringRef name;
1802+
if (archiveName.empty() ||
1803+
dtltoAdjustMemberPathIfThinArchive(ctx, archiveName, path)) {
1804+
name = ss.save(path);
1805+
} else {
1806+
// ThinLTO assumes that all MemoryBufferRefs given to it have a unique
1807+
// name. If two archives define two members with the same name, this
1808+
// causes a collision which result in only one of the objects being taken
1809+
// into consideration at LTO time (which very likely causes undefined
1810+
// symbols later in the link stage). So we append file offset to make
1811+
// filename unique.
1812+
name = ss.save(archiveName + "(" + path::filename(path) + " at " +
1813+
utostr(offsetInArchive) + ")");
1814+
}
1815+
18111816
MemoryBufferRef mbref(mb.getBuffer(), name);
18121817

18131818
obj = CHECK2(lto::InputFile::create(mbref), this);

0 commit comments

Comments
 (0)