Skip to content

Commit ccc8ae3

Browse files
committed
[DTLTO][ELF][COFF] Archive support for DTLTO - Removed thin archives support from lld/ELF/InputFiles.cpp.
1 parent fa7376c commit ccc8ae3

File tree

1 file changed

+10
-48
lines changed

1 file changed

+10
-48
lines changed

lld/ELF/InputFiles.cpp

Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#include "llvm/ADT/CachedHashString.h"
2121
#include "llvm/ADT/STLExtras.h"
2222
#include "llvm/LTO/LTO.h"
23-
#include "llvm/Object/Archive.h"
2423
#include "llvm/Object/IRObjectFile.h"
2524
#include "llvm/Support/AArch64AttributeParser.h"
2625
#include "llvm/Support/ARMAttributeParser.h"
@@ -1812,39 +1811,6 @@ static uint8_t getOsAbi(const Triple &t) {
18121811
}
18131812
}
18141813

1815-
// For DTLTO, bitcode member names must be valid paths to files on disk.
1816-
// For thin archives, resolve `memberPath` relative to the archive's location.
1817-
// Returns true if adjusted; false otherwise. Non-thin archives are unsupported.
1818-
static bool dtltoAdjustMemberPathIfThinArchive(Ctx &ctx, StringRef archivePath,
1819-
std::string &memberPath) {
1820-
assert(!archivePath.empty());
1821-
1822-
if (ctx.arg.dtltoDistributor.empty())
1823-
return false;
1824-
1825-
// Read the archive header to determine if it's a thin archive.
1826-
auto bufferOrErr =
1827-
MemoryBuffer::getFileSlice(archivePath, sizeof(ThinArchiveMagic) - 1, 0);
1828-
if (std::error_code ec = bufferOrErr.getError()) {
1829-
ErrAlways(ctx) << "cannot open " << archivePath << ": " << ec.message();
1830-
return false;
1831-
}
1832-
1833-
if (!bufferOrErr->get()->getBuffer().starts_with(ThinArchiveMagic))
1834-
return false;
1835-
1836-
SmallString<128> resolvedPath;
1837-
if (path::is_relative(memberPath)) {
1838-
resolvedPath = path::parent_path(archivePath);
1839-
path::append(resolvedPath, memberPath);
1840-
} else
1841-
resolvedPath = memberPath;
1842-
1843-
path::remove_dots(resolvedPath, /*remove_dot_dot=*/true);
1844-
memberPath = resolvedPath.str();
1845-
return true;
1846-
}
1847-
18481814
BitcodeFile::BitcodeFile(Ctx &ctx, MemoryBufferRef mb, StringRef archiveName,
18491815
uint64_t offsetInArchive, bool lazy)
18501816
: InputFile(ctx, BitcodeKind, mb) {
@@ -1855,21 +1821,17 @@ BitcodeFile::BitcodeFile(Ctx &ctx, MemoryBufferRef mb, StringRef archiveName,
18551821
if (ctx.arg.thinLTOIndexOnly)
18561822
path = replaceThinLTOSuffix(ctx, mb.getBufferIdentifier());
18571823

1824+
// ThinLTO assumes that all MemoryBufferRefs given to it have a unique
1825+
// name. If two archives define two members with the same name, this
1826+
// causes a collision which result in only one of the objects being taken
1827+
// into consideration at LTO time (which very likely causes undefined
1828+
// symbols later in the link stage). So we append file offset to make
1829+
// filename unique.
18581830
StringSaver &ss = ctx.saver;
1859-
StringRef name;
1860-
if (archiveName.empty() ||
1861-
dtltoAdjustMemberPathIfThinArchive(ctx, archiveName, path)) {
1862-
name = ss.save(path);
1863-
} else {
1864-
// ThinLTO assumes that all MemoryBufferRefs given to it have a unique
1865-
// name. If two archives define two members with the same name, this
1866-
// causes a collision which result in only one of the objects being taken
1867-
// into consideration at LTO time (which very likely causes undefined
1868-
// symbols later in the link stage). So we append file offset to make
1869-
// filename unique.
1870-
name = ss.save(archiveName + "(" + path::filename(path) + " at " +
1871-
utostr(offsetInArchive) + ")");
1872-
}
1831+
StringRef name = archiveName.empty()
1832+
? ss.save(path)
1833+
: ss.save(archiveName + "(" + path::filename(path) +
1834+
" at " + utostr(offsetInArchive) + ")");
18731835

18741836
MemoryBufferRef mbref(mb.getBuffer(), name);
18751837

0 commit comments

Comments
 (0)