aboutsummaryrefslogtreecommitdiff
path: root/src/link.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-10-09 12:18:09 -0400
committerAndrew Kelley <superjoe30@gmail.com>2018-10-09 13:16:50 -0400
commit6b93495792678bd00a6205967bb2704a9a35e9c7 (patch)
tree9dd12653140fd7943c7d09dce22b0367a0caa73c /src/link.cpp
parent5a3c02137e6a15d3b8c1fb3595d55003ea44139a (diff)
downloadzig-6b93495792678bd00a6205967bb2704a9a35e9c7.tar.gz
zig-6b93495792678bd00a6205967bb2704a9a35e9c7.zip
more efficient builtin library code generation
* introduce --disable-pic option which can generally be allowed to be the default. compiler_rt.a and builtin.a get this option when you build a static executable. * compiler_rt and builtin libraries are not built for build-lib --static * posix_spawn instead of fork/execv * disable the error limit on LLD. Fixes the blank lines printed
Diffstat (limited to 'src/link.cpp')
-rw-r--r--src/link.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/link.cpp b/src/link.cpp
index c961042324..095d3d79d7 100644
--- a/src/link.cpp
+++ b/src/link.cpp
@@ -44,6 +44,7 @@ static Buf *build_a_raw(CodeGen *parent_gen, const char *aname, Buf *full_path)
codegen_set_strip(child_gen, parent_gen->strip_debug_symbols);
codegen_set_is_static(child_gen, true);
+ child_gen->disable_pic = parent_gen->disable_pic;
codegen_set_out_name(child_gen, buf_create_from_str(aname));
@@ -209,10 +210,9 @@ static void construct_linker_job_elf(LinkJob *lj) {
lj->args.append(getLDMOption(&g->zig_target));
bool is_lib = g->out_type == OutTypeLib;
- bool is_static = g->is_static || (!is_lib && g->link_libs_list.length == 0);
- bool shared = !is_static && is_lib;
+ bool shared = !g->is_static && is_lib;
Buf *soname = nullptr;
- if (is_static) {
+ if (g->is_static) {
if (g->zig_target.arch.arch == ZigLLVM_arm || g->zig_target.arch.arch == ZigLLVM_armeb ||
g->zig_target.arch.arch == ZigLLVM_thumb || g->zig_target.arch.arch == ZigLLVM_thumbeb)
{
@@ -236,7 +236,7 @@ static void construct_linker_job_elf(LinkJob *lj) {
if (lj->link_in_crt) {
const char *crt1o;
const char *crtbegino;
- if (is_static) {
+ if (g->is_static) {
crt1o = "crt1.o";
crtbegino = "crtbeginT.o";
} else {
@@ -287,7 +287,7 @@ static void construct_linker_job_elf(LinkJob *lj) {
lj->args.append(buf_ptr(g->libc_static_lib_dir));
}
- if (!is_static) {
+ if (!g->is_static) {
if (g->dynamic_linker != nullptr) {
assert(buf_len(g->dynamic_linker) != 0);
lj->args.append("-dynamic-linker");
@@ -309,7 +309,7 @@ static void construct_linker_job_elf(LinkJob *lj) {
lj->args.append((const char *)buf_ptr(g->link_objects.at(i)));
}
- if (g->out_type == OutTypeExe || g->out_type == OutTypeLib) {
+ if (g->out_type == OutTypeExe || (g->out_type == OutTypeLib && !g->is_static)) {
if (g->libc_link_lib == nullptr) {
Buf *builtin_a_path = build_a(g, "builtin");
lj->args.append(buf_ptr(builtin_a_path));
@@ -339,7 +339,7 @@ static void construct_linker_job_elf(LinkJob *lj) {
// libc dep
if (g->libc_link_lib != nullptr) {
- if (is_static) {
+ if (g->is_static) {
lj->args.append("--start-group");
lj->args.append("-lgcc");
lj->args.append("-lgcc_eh");
@@ -540,7 +540,7 @@ static void construct_linker_job_coff(LinkJob *lj) {
lj->args.append((const char *)buf_ptr(g->link_objects.at(i)));
}
- if (g->out_type == OutTypeExe || g->out_type == OutTypeLib) {
+ if (g->out_type == OutTypeExe || (g->out_type == OutTypeLib && !g->is_static)) {
if (g->libc_link_lib == nullptr) {
Buf *builtin_a_path = build_a(g, "builtin");
lj->args.append(buf_ptr(builtin_a_path));
@@ -872,7 +872,7 @@ static void construct_linker_job_macho(LinkJob *lj) {
}
// compiler_rt on darwin is missing some stuff, so we still build it and rely on LinkOnce
- if (g->out_type == OutTypeExe || g->out_type == OutTypeLib) {
+ if (g->out_type == OutTypeExe || (g->out_type == OutTypeLib && !g->is_static)) {
Buf *compiler_rt_o_path = build_compiler_rt(g);
lj->args.append(buf_ptr(compiler_rt_o_path));
}
@@ -969,6 +969,7 @@ void codegen_link(CodeGen *g) {
lj.link_in_crt = (g->libc_link_lib != nullptr && g->out_type == OutTypeExe);
+ lj.args.append("-error-limit=0");
construct_linker_job(&lj);