Skip to content

Commit

Permalink
Accept --build-id=fast for the sake of compatibility with lld
Browse files Browse the repository at this point in the history
Fixes #1328
  • Loading branch information
rui314 committed Aug 13, 2024
1 parent 6248d96 commit afc52ee
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/mold.md
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,13 @@ but as `-o magic`.
The `--no-as-needed` option restores the default behavior for subsequent
files.

* `--build-id`=[ `md5` | `sha1` | `sha256` | `uuid` | `0x`_hexstring_ | `none` ]:
* `--build-id`=[ `md5` | `sha1` | `sha256` | `fast` | `uuid` | `0x`_hexstring_ | `none` ]:
Create a `.note.gnu.build-id` section containing a byte string to uniquely
identify an output file. `sha256` compute a 256-bit cryptographic hash of an
output file and set it to build-id. `md5` and `sha1` compute the same hash
but truncate it to 128 and 160 bits, respectively, before setting it to
build-id. `uuid` sets a random 128-bit UUID. `0x`_hexstring_ sets
_hexstring_.
_hexstring_. `fast` is a synonym for `sha256`.

* `--build-id`:
Synonym for `--build-id=sha256`.
Expand Down
4 changes: 2 additions & 2 deletions elf/cmdline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ inline const char helpmsg[] = R"(
--no-apply-dynamic-relocs
--as-needed Only set DT_NEEDED if used
--no-as-needed
--build-id [none,md5,sha1,sha256,uuid,HEXSTRING]
--build-id [none,md5,sha1,sha256,fast,uuid,HEXSTRING]
Generate build ID
--no-build-id
--chroot DIR Set a given path to the root directory
Expand Down Expand Up @@ -1232,7 +1232,7 @@ std::vector<std::string> parse_nonpositional_args(Context<E> &ctx) {
} else if (arg == "sha1") {
ctx.arg.build_id.kind = BuildId::HASH;
ctx.arg.build_id.hash_size = 20;
} else if (arg == "sha256") {
} else if (arg == "sha256" || arg == "fast") {
ctx.arg.build_id.kind = BuildId::HASH;
ctx.arg.build_id.hash_size = 32;
} else if (arg.starts_with("0x") || arg.starts_with("0X")) {
Expand Down
3 changes: 3 additions & 0 deletions test/elf/build-id.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ readelf -n $t/exe | grep -q 'GNU.*0x00000014.*NT_GNU_BUILD_ID'
$CC -B. -o $t/exe $t/a.c -Wl,-build-id=sha256
readelf -n $t/exe | grep -q 'GNU.*0x00000020.*NT_GNU_BUILD_ID'

$CC -B. -o $t/exe $t/a.c -Wl,-build-id=fast
readelf -n $t/exe | grep -q 'GNU.*0x00000020.*NT_GNU_BUILD_ID'

$CC -B. -o $t/exe $t/a.c -Wl,-build-id=0xdeadbeefdeadbeef
readelf -n $t/exe | grep -q 'Build ID: deadbeefdeadbeef'

0 comments on commit afc52ee

Please sign in to comment.