mirror of
https://github.com/rui314/mold.git
synced 2024-09-21 09:57:18 +03:00
[Mach-O] Add a stub for Mach-O
This commit is contained in:
parent
6cf0a010ec
commit
cab0ccf0bd
12
Makefile
12
Makefile
@ -17,9 +17,9 @@ CPPFLAGS = -g -pthread -std=c++20 -fPIE \
|
||||
LDFLAGS += $(EXTRA_LDFLAGS)
|
||||
LIBS = -pthread -lz -lxxhash -ldl -lm
|
||||
|
||||
SRCS=$(wildcard elf/*.cc)
|
||||
HEADERS=$(wildcard elf/*.h)
|
||||
OBJS=$(SRCS:elf/%.cc=out/elf/%.o)
|
||||
SRCS=$(wildcard *.cc elf/*.cc macho/*.cc)
|
||||
HEADERS=$(wildcard *.h elf/*.h macho/*.h)
|
||||
OBJS=$(SRCS:%.cc=out/%.o)
|
||||
|
||||
PREFIX ?= /usr
|
||||
DEST = $(DESTDIR)$(PREFIX)
|
||||
@ -79,13 +79,17 @@ mold: $(OBJS) $(MIMALLOC_LIB) $(TBB_LIB)
|
||||
mold-wrapper.so: elf/mold-wrapper.c Makefile
|
||||
$(CC) -fPIC -shared -o $@ $< -ldl
|
||||
|
||||
out/elf/%.o: elf/%.cc $(HEADERS) Makefile out/elf/.keep
|
||||
out/%.o: %.cc $(HEADERS) Makefile out/elf/.keep out/macho/.keep
|
||||
$(CXX) $(CPPFLAGS) -c -o $@ $<
|
||||
|
||||
out/elf/.keep:
|
||||
mkdir -p out/elf
|
||||
touch $@
|
||||
|
||||
out/macho/.keep:
|
||||
mkdir -p out/macho
|
||||
touch $@
|
||||
|
||||
$(MIMALLOC_LIB):
|
||||
mkdir -p out/mimalloc
|
||||
(cd out/mimalloc; CFLAGS=-DMI_USE_ENVIRON=0 cmake -G'Unix Makefiles' ../../third-party/mimalloc)
|
||||
|
17
elf/main.cc
17
elf/main.cc
@ -323,7 +323,7 @@ static void show_stats(Context<E> &ctx) {
|
||||
}
|
||||
|
||||
template <typename E>
|
||||
int do_main(int argc, char **argv) {
|
||||
int elf_main(int argc, char **argv) {
|
||||
Context<E> ctx;
|
||||
|
||||
// Process -run option first. process_run_subcommand() does not return.
|
||||
@ -340,9 +340,9 @@ int do_main(int argc, char **argv) {
|
||||
if (ctx.arg.emulation != E::e_machine) {
|
||||
switch (ctx.arg.emulation) {
|
||||
case EM_386:
|
||||
return do_main<I386>(argc, argv);
|
||||
return elf_main<I386>(argc, argv);
|
||||
case EM_AARCH64:
|
||||
return do_main<AARCH64>(argc, argv);
|
||||
return elf_main<AARCH64>(argc, argv);
|
||||
}
|
||||
unreachable(ctx);
|
||||
}
|
||||
@ -673,18 +673,11 @@ int do_main(int argc, char **argv) {
|
||||
|
||||
#define INSTANTIATE(E) \
|
||||
template void read_file(Context<E> &, MemoryMappedFile<E> *); \
|
||||
template std::string_view save_string(Context<E> &, const std::string &)
|
||||
template std::string_view save_string(Context<E> &, const std::string &); \
|
||||
template int elf_main<E>(int, char **);
|
||||
|
||||
INSTANTIATE(X86_64);
|
||||
INSTANTIATE(I386);
|
||||
INSTANTIATE(AARCH64);
|
||||
|
||||
} // namespace mold::elf
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
std::string_view cmd = mold::elf::path_filename(argv[0]);
|
||||
if (cmd == "ld" || cmd == "mold" || cmd == "ld.mold")
|
||||
return mold::elf::do_main<mold::elf::X86_64>(argc, argv);
|
||||
std::cerr << "mold: unknown command: " << argv[0] << "\n";
|
||||
exit(1);
|
||||
}
|
||||
|
@ -1671,6 +1671,9 @@ std::regex glob_to_regex(std::string_view pat);
|
||||
std::string errno_string();
|
||||
std::string get_version_string();
|
||||
|
||||
template <typename E>
|
||||
int elf_main(int argc, char **argv);
|
||||
|
||||
//
|
||||
// Error output
|
||||
//
|
||||
|
9
macho/main.cc
Normal file
9
macho/main.cc
Normal file
@ -0,0 +1,9 @@
|
||||
#include "mold.h"
|
||||
|
||||
namespace mold::macho {
|
||||
|
||||
int macho_main(int argc, char **argv) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
5
macho/mold.h
Normal file
5
macho/mold.h
Normal file
@ -0,0 +1,5 @@
|
||||
namespace mold::macho {
|
||||
|
||||
int macho_main(int argc, char **argv);
|
||||
|
||||
} // namespace mold::macho
|
14
main.cc
Normal file
14
main.cc
Normal file
@ -0,0 +1,14 @@
|
||||
#include "elf/mold.h"
|
||||
#include "macho/mold.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
std::string_view cmd = mold::elf::path_filename(argv[0]);
|
||||
|
||||
if (cmd == "ld" || cmd == "mold" || cmd == "ld.mold")
|
||||
return mold::elf::elf_main<mold::elf::X86_64>(argc, argv);
|
||||
if (cmd == "ld64" || cmd == "ld64.mold")
|
||||
return mold::macho::macho_main(argc, argv);
|
||||
|
||||
std::cerr << "mold: unknown command: " << argv[0] << "\n";
|
||||
exit(1);
|
||||
}
|
Loading…
Reference in New Issue
Block a user