1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-20 09:27:45 +03:00

[Mach-O] Set mold's version to LC_BUILD_VERSION

I chose 0x6d6f6c64 as a magic number without coordinating with other
tools or Apple, but it should be fine.
This commit is contained in:
Rui Ueyama 2022-06-26 13:11:50 +08:00
parent 831f872886
commit fe72463f55
5 changed files with 32 additions and 4 deletions

View File

@ -119,7 +119,7 @@ static i64 parse_platform(Context<E> &ctx, std::string_view arg) {
}
template <typename E>
static i64 parse_version(Context<E> &ctx, std::string_view arg) {
i64 parse_version(Context<E> &ctx, std::string_view arg) {
static std::regex re(R"((\d+)(?:\.(\d+))?(?:\.(\d+))?)",
std::regex_constants::ECMAScript);
std::cmatch m;
@ -483,7 +483,8 @@ std::vector<std::string> parse_nonpositional_args(Context<E> &ctx) {
return remaining;
}
#define INSTANTIATE(E) \
#define INSTANTIATE(E) \
template i64 parse_version(Context<E> &, std::string_view); \
template std::vector<std::string> parse_nonpositional_args(Context<E> &)
INSTANTIATE_ALL;

View File

@ -317,6 +317,7 @@ static constexpr u32 PLATFORM_DRIVERKIT = 10;
static constexpr u32 TOOL_CLANG = 1;
static constexpr u32 TOOL_SWIFT = 2;
static constexpr u32 TOOL_LD = 3;
static constexpr u32 TOOL_MOLD = 0x6d6f6c64; // Hex in "mold"
static constexpr u32 ARM64_RELOC_UNSIGNED = 0;
static constexpr u32 ARM64_RELOC_SUBTRACTOR = 1;

View File

@ -753,6 +753,9 @@ TextDylib parse_tbd(Context<E> &ctx, MappedFile<Context<E>> *mf);
// cmdline.cc
//
template <typename E>
i64 parse_version(Context<E> &ctx, std::string_view arg);
template <typename E>
std::vector<std::string> parse_nonpositional_args(Context<E> &ctx);

View File

@ -121,8 +121,8 @@ static std::vector<u8> create_build_version_cmd(Context<E> &ctx) {
cmd.ntools = 1;
BuildToolVersion &tool = *(BuildToolVersion *)(buf.data() + sizeof(cmd));
tool.tool = 3;
tool.version = 0x28a0900;
tool.tool = TOOL_MOLD;
tool.version = parse_version(ctx, MOLD_VERSION);
return buf;
}

23
test/macho/lc-build-version.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
export LC_ALL=C
set -e
CC="${TEST_CC:-cc}"
CXX="${TEST_CXX:-c++}"
GCC="${TEST_GCC:-gcc}"
GXX="${TEST_GXX:-g++}"
OBJDUMP="${OBJDUMP:-objdump}"
MACHINE="${MACHINE:-$(uname -m)}"
testname=$(basename "$0" .sh)
echo -n "Testing $testname ... "
cd "$(dirname "$0")"/../..
t=out/test/macho/$testname
mkdir -p $t
cat <<EOF | $CC -o $t/a.o -c -xc -
int main() {}
EOF
clang --ld-path=./ld64 -o $t/exe $t/a.o
otool -l $t/exe | grep -q 'tool 1836018788'
echo OK