mirror of
https://github.com/rui314/mold.git
synced 2024-09-20 01:18:53 +03:00
[Mach-O] Add -object_path_lto
This commit is contained in:
parent
8cf514408b
commit
f730dde6e7
@ -55,6 +55,7 @@ Options:
|
||||
-no_deduplicate Ignored
|
||||
-no_uuid Do not generate an LC_UUID load command
|
||||
-o <FILE> Set output filename
|
||||
-object_path_lto <FILE> Write a LTO temporary file to a given path
|
||||
-pagezero_size <SIZE> Specify the size of the __PAGEZERO segment
|
||||
-platform_version <PLATFORM> <MIN_VERSION> <SDK_VERSION>
|
||||
Set platform, platform version and SDK version
|
||||
@ -293,6 +294,8 @@ std::vector<std::string> parse_nonpositional_args(Context<E> &ctx) {
|
||||
ctx.arg.uuid = UUID_NONE;
|
||||
} else if (read_arg("-o")) {
|
||||
ctx.arg.output = arg;
|
||||
} else if (read_arg("-object_path_lto")) {
|
||||
ctx.arg.object_path_lto = arg;
|
||||
} else if (read_hex("-pagezero_size")) {
|
||||
pagezero_size = hex_arg;
|
||||
} else if (read_flag("-perf")) {
|
||||
|
12
macho/lto.cc
12
macho/lto.cc
@ -2,6 +2,7 @@
|
||||
#include "mold.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <dlfcn.h>
|
||||
|
||||
namespace mold::macho {
|
||||
@ -118,6 +119,17 @@ void do_lto(Context<E> &ctx) {
|
||||
// Run the compiler backend to do LTO.
|
||||
size_t size;
|
||||
u8 *data = (u8 *)ctx.lto.codegen_compile(cg, &size);
|
||||
if (!data)
|
||||
Fatal(ctx) << "lto_codegen_compile failed: " << ctx.lto.get_error_message();
|
||||
|
||||
if (!ctx.arg.object_path_lto.empty()) {
|
||||
FILE *out = fopen(ctx.arg.object_path_lto.c_str(), "w");
|
||||
if (!out)
|
||||
Fatal(ctx) << "-object_path_lto: cannot open " << ctx.arg.object_path_lto
|
||||
<< ": " << errno_string();
|
||||
fwrite(data, size, 1, out);
|
||||
fclose(out);
|
||||
}
|
||||
|
||||
// Remove bitcode object files from ctx.objs.
|
||||
for (ObjectFile<E> *file : ctx.objs) {
|
||||
|
@ -874,6 +874,7 @@ struct Context {
|
||||
std::string install_name;
|
||||
std::string lto_library;
|
||||
std::string map;
|
||||
std::string object_path_lto;
|
||||
std::string output = "a.out";
|
||||
std::vector<SectCreateOption> sectcreate;
|
||||
std::vector<std::string> U;
|
||||
|
27
test/macho/object-path-lto.sh
Executable file
27
test/macho/object-path-lto.sh
Executable file
@ -0,0 +1,27 @@
|
||||
#!/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 - -flto
|
||||
#include <stdio.h>
|
||||
int main() {
|
||||
printf("Hello world\n");
|
||||
}
|
||||
EOF
|
||||
|
||||
clang --ld-path=./ld64 -o $t/exe $t/a.o -flto -Wl,-object_path_lto,$t/obj
|
||||
$t/exe | grep -q 'Hello world'
|
||||
otool -l $t/obj > /dev/null
|
||||
|
||||
echo OK
|
Loading…
Reference in New Issue
Block a user