Skip to content

Commit c8e5354

Browse files
committed
Revert "[WebAssembly] Implement build-id feature"
This reverts commit 41e3146 due to a build failure on Windows.
1 parent bdbebef commit c8e5354

File tree

7 files changed

+0
-256
lines changed

7 files changed

+0
-256
lines changed

lld/test/wasm/build-id.test

Lines changed: 0 additions & 60 deletions
This file was deleted.

lld/wasm/Config.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ namespace wasm {
2626
// For --unresolved-symbols.
2727
enum class UnresolvedPolicy { ReportError, Warn, Ignore, ImportDynamic };
2828

29-
// For --build-id.
30-
enum class BuildIdKind { None, Fast, Sha1, Hexstring, Uuid };
31-
3229
// This struct contains the global configuration for the linker.
3330
// Most fields are direct mapping from the command line options
3431
// and such fields have the same name as the corresponding options.
@@ -75,7 +72,6 @@ struct Configuration {
7572
llvm::StringRef thinLTOJobs;
7673
bool ltoDebugPassManager;
7774
UnresolvedPolicy unresolvedSymbols;
78-
BuildIdKind buildId = BuildIdKind::None;
7975

8076
llvm::StringRef entry;
8177
llvm::StringRef mapFile;
@@ -89,7 +85,6 @@ struct Configuration {
8985
llvm::CachePruningPolicy thinLTOCachePolicy;
9086
std::optional<std::vector<std::string>> features;
9187
std::optional<std::vector<std::string>> extraFeatures;
92-
llvm::SmallVector<uint8_t, 0> buildIdVector;
9388

9489
// The following config options do not directly correspond to any
9590
// particular command line options.

lld/wasm/Driver.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -385,33 +385,6 @@ static UnresolvedPolicy getUnresolvedSymbolPolicy(opt::InputArgList &args) {
385385
return errorOrWarn;
386386
}
387387

388-
// Parse --build-id or --build-id=<style>. We handle "tree" as a
389-
// synonym for "sha1" because all our hash functions including
390-
// -build-id=sha1 are actually tree hashes for performance reasons.
391-
static std::pair<BuildIdKind, SmallVector<uint8_t, 0>>
392-
getBuildId(opt::InputArgList &args) {
393-
auto *arg = args.getLastArg(OPT_build_id, OPT_build_id_eq);
394-
if (!arg)
395-
return {BuildIdKind::None, {}};
396-
397-
if (arg->getOption().getID() == OPT_build_id)
398-
return {BuildIdKind::Fast, {}};
399-
400-
StringRef s = arg->getValue();
401-
if (s == "fast")
402-
return {BuildIdKind::Fast, {}};
403-
if (s == "sha1" || s == "tree")
404-
return {BuildIdKind::Sha1, {}};
405-
if (s == "uuid")
406-
return {BuildIdKind::Uuid, {}};
407-
if (s.startswith("0x"))
408-
return {BuildIdKind::Hexstring, parseHex(s.substr(2))};
409-
410-
if (s != "none")
411-
error("unknown --build-id style: " + s);
412-
return {BuildIdKind::None, {}};
413-
}
414-
415388
// Initializes Config members by the command line options.
416389
static void readConfigs(opt::InputArgList &args) {
417390
config->bsymbolic = args.hasArg(OPT_Bsymbolic);
@@ -546,8 +519,6 @@ static void readConfigs(opt::InputArgList &args) {
546519

547520
if (args.hasArg(OPT_print_map))
548521
config->mapFile = "-";
549-
550-
std::tie(config->buildId, config->buildIdVector) = getBuildId(args);
551522
}
552523

553524
// Some Config members do not directly correspond to any particular

lld/wasm/Options.td

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ def Bdynamic: F<"Bdynamic">, HelpText<"Link against shared libraries (default)">
4242

4343
def Bstatic: F<"Bstatic">, HelpText<"Do not link against shared libraries">;
4444

45-
def build_id: F<"build-id">, HelpText<"Alias for --build-id=fast">;
46-
47-
def build_id_eq: J<"build-id=">, HelpText<"Generate build ID note">,
48-
MetaVarName<"[fast,sha1,uuid,0x<hexstring>]">;
49-
5045
defm color_diagnostics: B<"color-diagnostics",
5146
"Alias for --color-diagnostics=always",
5247
"Alias for --color-diagnostics=never">;

lld/wasm/SyntheticSections.cpp

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -888,39 +888,5 @@ void RelocSection::writeBody() {
888888
sec->writeRelocations(bodyOutputStream);
889889
}
890890

891-
static size_t getHashSize() {
892-
switch (config->buildId) {
893-
case BuildIdKind::Fast:
894-
case BuildIdKind::Uuid:
895-
return 16;
896-
case BuildIdKind::Sha1:
897-
return 20;
898-
case BuildIdKind::Hexstring:
899-
return config->buildIdVector.size();
900-
case BuildIdKind::None:
901-
return 0;
902-
}
903-
}
904-
905-
BuildIdSection::BuildIdSection()
906-
: SyntheticSection(llvm::wasm::WASM_SEC_CUSTOM, buildIdSectionName),
907-
hashSize(getHashSize()) {}
908-
909-
void BuildIdSection::writeBody() {
910-
LLVM_DEBUG(llvm::dbgs() << "BuildId writebody\n");
911-
// Write hash size
912-
auto &os = bodyOutputStream;
913-
writeUleb128(os, hashSize, "build id size");
914-
writeBytes(os, std::vector<char>(hashSize, ' ').data(), hashSize,
915-
"placeholder");
916-
}
917-
918-
void BuildIdSection::writeBuildId(llvm::ArrayRef<uint8_t> buf) {
919-
assert(buf.size() == hashSize);
920-
LLVM_DEBUG(dbgs() << "buildid write " << buf.size() << " "
921-
<< hashPlaceholderPtr << '\n');
922-
memcpy(hashPlaceholderPtr, buf.data(), hashSize);
923-
}
924-
925891
} // namespace wasm
926892
} // namespace lld

lld/wasm/SyntheticSections.h

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -429,34 +429,6 @@ class RelocSection : public SyntheticSection {
429429
OutputSection *sec;
430430
};
431431

432-
class BuildIdSection : public SyntheticSection {
433-
public:
434-
BuildIdSection();
435-
void writeBody() override;
436-
bool isNeeded() const override {
437-
return config->buildId != BuildIdKind::None;
438-
}
439-
void writeBuildId(llvm::ArrayRef<uint8_t> buf);
440-
void writeTo(uint8_t *buf) override {
441-
LLVM_DEBUG(llvm::dbgs() << "BuildId writeto buf " << buf << " offset "
442-
<< offset << " headersize " << header.size() << '\n');
443-
// The actual build ID is derived from a hash of all of the output
444-
// sections, so it can't be calculated until they are written. Here
445-
// we write the section leaving zeros in place of the hash.
446-
SyntheticSection::writeTo(buf);
447-
// Calculate and store the location where the hash will be written.
448-
hashPlaceholderPtr = buf + offset + header.size() +
449-
+sizeof(buildIdSectionName) /*name string*/ +
450-
1 /* hash size */;
451-
}
452-
453-
const uint32_t hashSize;
454-
455-
private:
456-
static constexpr char buildIdSectionName[] = "build_id";
457-
uint8_t *hashPlaceholderPtr = nullptr;
458-
};
459-
460432
// Linker generated output sections
461433
struct OutStruct {
462434
DylinkSection *dylinkSec;
@@ -475,7 +447,6 @@ struct OutStruct {
475447
NameSection *nameSec;
476448
ProducersSection *producersSec;
477449
TargetFeaturesSection *targetFeaturesSec;
478-
BuildIdSection *buildIdSec;
479450
};
480451

481452
extern OutStruct out;

lld/wasm/Writer.cpp

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
#include "SymbolTable.h"
1818
#include "SyntheticSections.h"
1919
#include "WriterUtils.h"
20-
#include "lld/Common/Arrays.h"
2120
#include "lld/Common/CommonLinkerContext.h"
2221
#include "lld/Common/Strings.h"
23-
#include "llvm/ADT/ArrayRef.h"
2422
#include "llvm/ADT/DenseSet.h"
2523
#include "llvm/ADT/SmallSet.h"
2624
#include "llvm/ADT/SmallVector.h"
@@ -32,9 +30,6 @@
3230
#include "llvm/Support/FormatVariadic.h"
3331
#include "llvm/Support/LEB128.h"
3432
#include "llvm/Support/Parallel.h"
35-
#include "llvm/Support/RandomNumberGenerator.h"
36-
#include "llvm/Support/SHA1.h"
37-
#include "llvm/Support/xxhash.h"
3833

3934
#include <cstdarg>
4035
#include <map>
@@ -108,7 +103,6 @@ class Writer {
108103

109104
void writeHeader();
110105
void writeSections();
111-
void writeBuildId();
112106

113107
uint64_t fileSize = 0;
114108

@@ -225,91 +219,6 @@ void Writer::writeSections() {
225219
});
226220
}
227221

228-
// Computes a hash value of Data using a given hash function.
229-
// In order to utilize multiple cores, we first split data into 1MB
230-
// chunks, compute a hash for each chunk, and then compute a hash value
231-
// of the hash values.
232-
233-
static void
234-
computeHash(llvm::MutableArrayRef<uint8_t> hashBuf,
235-
llvm::ArrayRef<uint8_t> data,
236-
std::function<void(uint8_t *dest, ArrayRef<uint8_t> arr)> hashFn) {
237-
std::vector<ArrayRef<uint8_t>> chunks = split(data, 1024 * 1024);
238-
std::vector<uint8_t> hashes(chunks.size() * hashBuf.size());
239-
240-
// Compute hash values.
241-
parallelFor(0, chunks.size(), [&](size_t i) {
242-
hashFn(hashes.data() + i * hashBuf.size(), chunks[i]);
243-
});
244-
245-
// Write to the final output buffer.
246-
hashFn(hashBuf.data(), hashes);
247-
}
248-
249-
static void makeUUID(unsigned version, llvm::ArrayRef<uint8_t> fileHash,
250-
llvm::MutableArrayRef<uint8_t> output) {
251-
assert(version == 4 || version == 5 && "Unknown UUID version");
252-
assert(output.size() == 16 && "Wrong size for UUID output");
253-
if (version == 5) {
254-
// Build a valid v5 UUID from a hardcoded (randomly-generated) namespace
255-
// UUID, and the computed hash of the output.
256-
std::vector<uint8_t> namespaceUUID{0xA1, 0xFA, 0x48, 0x2D, 0x0E, 0x22,
257-
0x03, 0x8D, 0x33, 0x8B, 0x52, 0x1C,
258-
0xD6, 0xD2, 0x12, 0xB2};
259-
SHA1 sha;
260-
sha.update(namespaceUUID);
261-
sha.update(fileHash);
262-
auto s = sha.final();
263-
std::copy(s.begin(), &s[output.size()], output.begin());
264-
} else if (version == 4) {
265-
if (auto ec = llvm::getRandomBytes(output.data(), output.size()))
266-
error("entropy source failure: " + ec.message());
267-
}
268-
// Set the UUID version and variant fields.
269-
// The version is the upper nibble of byte 6 (0b0101xxxx or 0b0100xxxx)
270-
output[6] = (static_cast<uint8_t>(version) << 4) | (output[6] & 0xF);
271-
272-
// The variant is DCE 1.1/ISO 11578 (0b10xxxxxx)
273-
output[8] &= 0xBF;
274-
output[8] |= 0x80;
275-
}
276-
277-
void Writer::writeBuildId() {
278-
if (!out.buildIdSec->isNeeded())
279-
return;
280-
if (config->buildId == BuildIdKind::Hexstring) {
281-
out.buildIdSec->writeBuildId(config->buildIdVector);
282-
return;
283-
}
284-
285-
// Compute a hash of all sections of the output file.
286-
size_t hashSize = out.buildIdSec->hashSize;
287-
std::vector<uint8_t> buildId(hashSize);
288-
llvm::ArrayRef<uint8_t> buf{buffer->getBufferStart(), size_t(fileSize)};
289-
290-
switch (config->buildId) {
291-
case BuildIdKind::Fast:{
292-
std::vector<uint8_t> fileHash(8);
293-
computeHash(fileHash, buf, [](uint8_t *dest, ArrayRef<uint8_t> arr) {
294-
support::endian::write64le(dest, xxHash64(arr));
295-
});
296-
makeUUID(5, fileHash, buildId);
297-
break;
298-
}
299-
case BuildIdKind::Sha1:
300-
computeHash(buildId, buf, [&](uint8_t *dest, ArrayRef<uint8_t> arr) {
301-
memcpy(dest, SHA1::hash(arr).data(), hashSize);
302-
});
303-
break;
304-
case BuildIdKind::Uuid:
305-
makeUUID(4, {}, buildId);
306-
break;
307-
default:
308-
llvm_unreachable("unknown BuildIdKind");
309-
}
310-
out.buildIdSec->writeBuildId(buildId);
311-
}
312-
313222
static void setGlobalPtr(DefinedGlobal *g, uint64_t memoryPtr) {
314223
LLVM_DEBUG(dbgs() << "setGlobalPtr " << g->getName() << " -> " << memoryPtr << "\n");
315224
g->global->setPointerValue(memoryPtr);
@@ -547,7 +456,6 @@ void Writer::addSections() {
547456
addSection(out.nameSec);
548457
addSection(out.producersSec);
549458
addSection(out.targetFeaturesSec);
550-
addSection(out.buildIdSec);
551459
}
552460

553461
void Writer::finalizeSections() {
@@ -1669,7 +1577,6 @@ void Writer::createSyntheticSections() {
16691577
out.elemSec = make<ElemSection>();
16701578
out.producersSec = make<ProducersSection>();
16711579
out.targetFeaturesSec = make<TargetFeaturesSection>();
1672-
out.buildIdSec = make<BuildIdSection>();
16731580
}
16741581

16751582
void Writer::createSyntheticSectionsPostLayout() {
@@ -1831,7 +1738,6 @@ void Writer::run() {
18311738

18321739
log("-- writeSections");
18331740
writeSections();
1834-
writeBuildId();
18351741
if (errorCount())
18361742
return;
18371743

0 commit comments

Comments
 (0)