authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-26 15:28:47-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-26 15:30:52-04:00
log6aeceec1f28ec4717af0659974d994cf1205915e
treeade5f3b1f8f1386af11cc981e358a34ed36f005e
parent28c31a8429f513f2d0e04ff5193faa8147721b19

add CLI option -Bsymbolic for binding global references locally


4 files changed, 25 insertions(+), 0 deletions(-)

src/all_types.hpp+1
......@@ -2270,6 +2270,7 @@ struct CodeGen {
22702270 CodeModel code_model;
22712271 OptionalBool linker_gc_sections;
22722272 OptionalBool linker_allow_shlib_undefined;
2273 OptionalBool linker_bind_global_refs_locally;
22732274 bool strip_debug_symbols;
22742275 bool is_test_build;
22752276 bool is_single_threaded;
src/codegen.cpp+1
......@@ -10685,6 +10685,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
1068510685 cache_buf_opt(ch, g->linker_optimization);
1068610686 cache_int(ch, g->linker_gc_sections);
1068710687 cache_int(ch, g->linker_allow_shlib_undefined);
10688 cache_int(ch, g->linker_bind_global_refs_locally);
1068810689 cache_bool(ch, g->linker_z_nodelete);
1068910690 cache_bool(ch, g->linker_z_defs);
1069010691 cache_usize(ch, g->stack_size_override);
src/link.cpp+16
......@@ -2086,6 +2086,14 @@ static void construct_linker_job_elf(LinkJob *lj) {
20862086 lj->args.append("--allow-shlib-undefined");
20872087 break;
20882088 }
2089 switch (g->linker_bind_global_refs_locally) {
2090 case OptionalBoolNull:
2091 case OptionalBoolFalse:
2092 break;
2093 case OptionalBoolTrue:
2094 lj->args.append("-Bsymbolic");
2095 break;
2096 }
20892097}
20902098
20912099static void construct_linker_job_wasm(LinkJob *lj) {
......@@ -2810,6 +2818,14 @@ static void construct_linker_job_macho(LinkJob *lj) {
28102818 lj->args.append("dynamic_lookup");
28112819 break;
28122820 }
2821 switch (g->linker_bind_global_refs_locally) {
2822 case OptionalBoolNull:
2823 case OptionalBoolFalse:
2824 break;
2825 case OptionalBoolTrue:
2826 lj->args.append("-Bsymbolic");
2827 break;
2828 }
28132829
28142830 for (size_t i = 0; i < g->framework_dirs.length; i += 1) {
28152831 const char *framework_dir = g->framework_dirs.at(i);
src/main.cpp+7
......@@ -132,6 +132,7 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {
132132 " --ver-major [ver] dynamic library semver major version\n"
133133 " --ver-minor [ver] dynamic library semver minor version\n"
134134 " --ver-patch [ver] dynamic library semver patch version\n"
135 " -Bsymbolic bind global references locally\n"
135136 "\n"
136137 "Test Options:\n"
137138 " --test-filter [text] skip tests that do not match filter\n"
......@@ -452,6 +453,7 @@ static int main0(int argc, char **argv) {
452453 Buf *linker_optimization = nullptr;
453454 OptionalBool linker_gc_sections = OptionalBoolNull;
454455 OptionalBool linker_allow_shlib_undefined = OptionalBoolNull;
456 OptionalBool linker_bind_global_refs_locally = OptionalBoolNull;
455457 bool linker_z_nodelete = false;
456458 bool linker_z_defs = false;
457459 size_t stack_size_override = 0;
......@@ -842,6 +844,8 @@ static int main0(int argc, char **argv) {
842844 buf_eql_str(arg, "-no-allow-shlib-undefined"))
843845 {
844846 linker_allow_shlib_undefined = OptionalBoolFalse;
847 } else if (buf_eql_str(arg, "-Bsymbolic")) {
848 linker_bind_global_refs_locally = OptionalBoolTrue;
845849 } else if (buf_eql_str(arg, "-z")) {
846850 i += 1;
847851 if (i >= linker_args.length) {
......@@ -1013,6 +1017,8 @@ static int main0(int argc, char **argv) {
10131017 want_single_threaded = true;;
10141018 } else if (strcmp(arg, "--bundle-compiler-rt") == 0) {
10151019 bundle_compiler_rt = true;
1020 } else if (strcmp(arg, "-Bsymbolic") == 0) {
1021 linker_bind_global_refs_locally = OptionalBoolTrue;
10161022 } else if (strcmp(arg, "--test-cmd-bin") == 0) {
10171023 test_exec_args.append(nullptr);
10181024 } else if (arg[1] == 'D' && arg[2] != 0) {
......@@ -1609,6 +1615,7 @@ static int main0(int argc, char **argv) {
16091615 g->linker_optimization = linker_optimization;
16101616 g->linker_gc_sections = linker_gc_sections;
16111617 g->linker_allow_shlib_undefined = linker_allow_shlib_undefined;
1618 g->linker_bind_global_refs_locally = linker_bind_global_refs_locally;
16121619 g->linker_z_nodelete = linker_z_nodelete;
16131620 g->linker_z_defs = linker_z_defs;
16141621 g->stack_size_override = stack_size_override;