1
1
mirror of https://github.com/rui314/mold.git synced 2024-11-12 23:48:51 +03:00

[Mach-O] wip

This commit is contained in:
Rui Ueyama 2021-10-23 16:49:06 +09:00
parent 794882435f
commit 5bac5f3c60
4 changed files with 14 additions and 16 deletions

View File

@ -53,12 +53,16 @@ static i64 parse_platform(Context &ctx, std::string_view arg) {
}
static i64 parse_version(Context &ctx, std::string_view arg) {
static std::regex re(R"(\d+(?:\.\d+(?:\.\d+)))",
static std::regex re(R"((\d+)(?:\.(\d+))?(?:\.(\d+))?)",
std::regex_constants::ECMAScript);
std::cmatch m;
if (!std::regex_match(arg.begin(), arg.end(), m, re))
Fatal(ctx) << "malformed version number: " << arg;
return (stoi(m[1]) << 16) | (stoi(m[2]) << 8) | stoi(m[3]);
i64 major = (m[1].length() == 0) ? 0 : stoi(m[1]);
i64 minor = (m[2].length() == 0) ? 0 : stoi(m[2]);
i64 patch = (m[3].length() == 0) ? 0 : stoi(m[3]);
return (major << 16) | (minor << 8) | patch;
}
void parse_nonpositional_args(Context &ctx,
@ -131,9 +135,9 @@ void parse_nonpositional_args(Context &ctx,
ctx.arg.demangle = true;
} else if (read_flag("-dynamic")) {
ctx.arg.dynamic = true;
} else if (read_flag("-lto_library")) {
} else if (read_joined("-l")) {
remaining.push_back("-l" + std::string(arg));
} else if (read_flag("-lto_library")) {
} else if (read_arg("-o")) {
ctx.arg.output = arg;
} else if (read_arg3("-platform_version")) {

View File

@ -117,16 +117,6 @@ static void fix_synthetic_symbol_values(Context &ctx) {
intern(ctx, "__dyld_private")->value = ctx.data.hdr.addr;
}
static void read_file(Context &ctx, MappedFile<Context> *mf) {
switch (get_file_type(mf)) {
case FileType::MACH_OBJ:
ctx.objs.push_back(ObjectFile::create(ctx, mf));
return;
default:
Fatal(ctx) << mf->name << ": unknown file type";
}
}
MappedFile<Context> *find_library(Context &ctx, std::string name) {
for (std::string dir : ctx.arg.library_paths) {
for (std::string ext : {".tbd", ".dylib", ".a"}) {
@ -144,8 +134,12 @@ static void read_input_files(Context &ctx, std::span<std::string> args) {
MappedFile<Context> *mf = find_library(ctx, arg.substr(2));
if (!mf)
Fatal(ctx) << "library not found: " << arg;
ctx.dylibs.push_back(DylibFile::create(ctx, mf));
} else {
read_file(ctx, MappedFile<Context>::must_open(ctx, arg));
MappedFile<Context> *mf = MappedFile<Context>::must_open(ctx, arg);
if (get_file_type(mf) != FileType::MACH_OBJ)
Fatal(ctx) << mf->name << ": unknown file type";
ctx.objs.push_back(ObjectFile::create(ctx, mf));
}
}
}

View File

@ -86,7 +86,7 @@ private:
DylibFile() = default;
};
std::ostream &operator<<(std::ostream &out, const ObjectFile &file);
std::ostream &operator<<(std::ostream &out, const InputFile &file);
//
// input-sections.cc

View File

@ -4,7 +4,7 @@
namespace mold::macho {
std::ostream &operator<<(std::ostream &out, const ObjectFile &file) {
std::ostream &operator<<(std::ostream &out, const InputFile &file) {
out << path_clean(file.mf->name);
return out;
}