From 264dd2eb579e78471c639baf698f7665ea016349 Mon Sep 17 00:00:00 2001 From: Marc Tiehuis Date: Sat, 21 Oct 2017 22:24:15 +0000 Subject: Set FreeBSD ELF OS/ABI when targeting Closes #553. --- src/link.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/link.cpp') diff --git a/src/link.cpp b/src/link.cpp index 424b06169e..613768cec8 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -150,6 +150,10 @@ static const char *getLDMOption(const ZigTarget *t) { if (t->env_type == ZigLLVM_GNUX32) { return "elf32_x86_64"; } + // Any target elf will use the freebsd osabi if suffixed with "_fbsd". + if (t->os == OsFreeBSD) { + return "elf_x86_64_fbsd"; + } return "elf_x86_64"; default: zig_unreachable(); -- cgit v1.2.3 From 831bb668955fa9d332f7beb1ea11f1c8028e5235 Mon Sep 17 00:00:00 2001 From: Greg V Date: Wed, 17 Oct 2018 22:21:16 +0300 Subject: Set up libc/rtld paths for FreeBSD --- src-self-hosted/libc_installation.zig | 2 +- src-self-hosted/target.zig | 9 ++++++++- src/analyze.cpp | 6 +++++- src/link.cpp | 3 +++ 4 files changed, 17 insertions(+), 3 deletions(-) (limited to 'src/link.cpp') diff --git a/src-self-hosted/libc_installation.zig b/src-self-hosted/libc_installation.zig index daab058223..86672a2b95 100644 --- a/src-self-hosted/libc_installation.zig +++ b/src-self-hosted/libc_installation.zig @@ -172,7 +172,7 @@ pub const LibCInstallation = struct.{ try group.call(findNativeStaticLibDir, self, loop); try group.call(findNativeDynamicLinker, self, loop); }, - builtin.Os.macosx => { + builtin.Os.macosx, builtin.Os.freebsd => { self.include_dir = try std.mem.dupe(loop.allocator, u8, "/usr/include"); }, else => @compileError("unimplemented: find libc for this OS"), diff --git a/src-self-hosted/target.zig b/src-self-hosted/target.zig index 44c98e79bf..0b6842490d 100644 --- a/src-self-hosted/target.zig +++ b/src-self-hosted/target.zig @@ -299,6 +299,13 @@ pub const Target = union(enum).{ pub fn getDynamicLinkerPath(self: Target) ?[]const u8 { const env = self.getEnviron(); const arch = self.getArch(); + const os = self.getOs(); + switch (os) { + builtin.Os.freebsd => { + return "/libexec/ld-elf.so.1"; + }, + else => {}, + } switch (env) { builtin.Environ.android => { if (self.is64bit()) { @@ -493,6 +500,7 @@ pub const Target = union(enum).{ builtin.Os.linux, builtin.Os.macosx, + builtin.Os.freebsd, builtin.Os.openbsd, builtin.Os.zen, => switch (id) { @@ -527,7 +535,6 @@ pub const Target = union(enum).{ builtin.Os.ananas, builtin.Os.cloudabi, builtin.Os.dragonfly, - builtin.Os.freebsd, builtin.Os.fuchsia, builtin.Os.ios, builtin.Os.kfreebsd, diff --git a/src/analyze.cpp b/src/analyze.cpp index e71369eac9..4d7fe1a656 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -4606,7 +4606,7 @@ void find_libc_include_path(CodeGen *g) { } } else if (g->zig_target.os == OsLinux) { g->libc_include_dir = get_linux_libc_include_path(); - } else if (g->zig_target.os == OsMacOSX) { + } else if (g->zig_target.os == OsMacOSX || g->zig_target.os == OsFreeBSD) { g->libc_include_dir = buf_create_from_str("/usr/include"); } else { // TODO find libc at runtime for other operating systems @@ -4652,6 +4652,8 @@ void find_libc_lib_path(CodeGen *g) { } else if (g->zig_target.os == OsLinux) { g->libc_lib_dir = get_linux_libc_lib_path("crt1.o"); + } else if (g->zig_target.os == OsFreeBSD) { + g->libc_lib_dir = buf_create_from_str("/usr/lib"); } else { zig_panic("Unable to determine libc lib path."); } @@ -4664,6 +4666,8 @@ void find_libc_lib_path(CodeGen *g) { return; } else if (g->zig_target.os == OsLinux) { g->libc_static_lib_dir = get_linux_libc_lib_path("crtbegin.o"); + } else if (g->zig_target.os == OsFreeBSD) { + g->libc_static_lib_dir = buf_create_from_str("/usr/lib"); } else { zig_panic("Unable to determine libc static lib path."); } diff --git a/src/link.cpp b/src/link.cpp index 613768cec8..0913b96a01 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -195,6 +195,9 @@ static Buf *try_dynamic_linker_path(const char *ld_name) { } static Buf *get_dynamic_linker_path(CodeGen *g) { + if (g->zig_target.os == OsFreeBSD) { + return buf_create_from_str("/libexec/ld-elf.so.1"); + } if (g->is_native_target && g->zig_target.arch.arch == ZigLLVM_x86_64) { static const char *ld_names[] = { "ld-linux-x86-64.so.2", -- cgit v1.2.3