diff --git a/docs/mold.md b/docs/mold.md index 2099c46f97..19e7c25b3c 100644 --- a/docs/mold.md +++ b/docs/mold.md @@ -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`. diff --git a/elf/cmdline.cc b/elf/cmdline.cc index 64a2ad90b9..12a745500c 100644 --- a/elf/cmdline.cc +++ b/elf/cmdline.cc @@ -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 @@ -1232,7 +1232,7 @@ std::vector parse_nonpositional_args(Context &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")) { diff --git a/test/elf/build-id.sh b/test/elf/build-id.sh index acff861e9a..d23109251c 100755 --- a/test/elf/build-id.sh +++ b/test/elf/build-id.sh @@ -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'