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 {...@@ -2270,6 +2270,7 @@ struct CodeGen {
2270 CodeModel code_model;2270 CodeModel code_model;
2271 OptionalBool linker_gc_sections;2271 OptionalBool linker_gc_sections;
2272 OptionalBool linker_allow_shlib_undefined;2272 OptionalBool linker_allow_shlib_undefined;
2273 OptionalBool linker_bind_global_refs_locally;
2273 bool strip_debug_symbols;2274 bool strip_debug_symbols;
2274 bool is_test_build;2275 bool is_test_build;
2275 bool is_single_threaded;2276 bool is_single_threaded;
src/codegen.cpp+1
...@@ -10685,6 +10685,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {...@@ -10685,6 +10685,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
10685 cache_buf_opt(ch, g->linker_optimization);10685 cache_buf_opt(ch, g->linker_optimization);
10686 cache_int(ch, g->linker_gc_sections);10686 cache_int(ch, g->linker_gc_sections);
10687 cache_int(ch, g->linker_allow_shlib_undefined);10687 cache_int(ch, g->linker_allow_shlib_undefined);
10688 cache_int(ch, g->linker_bind_global_refs_locally);
10688 cache_bool(ch, g->linker_z_nodelete);10689 cache_bool(ch, g->linker_z_nodelete);
10689 cache_bool(ch, g->linker_z_defs);10690 cache_bool(ch, g->linker_z_defs);
10690 cache_usize(ch, g->stack_size_override);10691 cache_usize(ch, g->stack_size_override);
src/link.cpp+16
...@@ -2086,6 +2086,14 @@ static void construct_linker_job_elf(LinkJob *lj) {...@@ -2086,6 +2086,14 @@ static void construct_linker_job_elf(LinkJob *lj) {
2086 lj->args.append("--allow-shlib-undefined");2086 lj->args.append("--allow-shlib-undefined");
2087 break;2087 break;
2088 }2088 }
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 }
2089}2097}
20902098
2091static void construct_linker_job_wasm(LinkJob *lj) {2099static void construct_linker_job_wasm(LinkJob *lj) {
...@@ -2810,6 +2818,14 @@ static void construct_linker_job_macho(LinkJob *lj) {...@@ -2810,6 +2818,14 @@ static void construct_linker_job_macho(LinkJob *lj) {
2810 lj->args.append("dynamic_lookup");2818 lj->args.append("dynamic_lookup");
2811 break;2819 break;
2812 }2820 }
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
2814 for (size_t i = 0; i < g->framework_dirs.length; i += 1) {2830 for (size_t i = 0; i < g->framework_dirs.length; i += 1) {
2815 const char *framework_dir = g->framework_dirs.at(i);2831 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) {...@@ -132,6 +132,7 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {
132 " --ver-major [ver] dynamic library semver major version\n"132 " --ver-major [ver] dynamic library semver major version\n"
133 " --ver-minor [ver] dynamic library semver minor version\n"133 " --ver-minor [ver] dynamic library semver minor version\n"
134 " --ver-patch [ver] dynamic library semver patch version\n"134 " --ver-patch [ver] dynamic library semver patch version\n"
135 " -Bsymbolic bind global references locally\n"
135 "\n"136 "\n"
136 "Test Options:\n"137 "Test Options:\n"
137 " --test-filter [text] skip tests that do not match filter\n"138 " --test-filter [text] skip tests that do not match filter\n"
...@@ -452,6 +453,7 @@ static int main0(int argc, char **argv) {...@@ -452,6 +453,7 @@ static int main0(int argc, char **argv) {
452 Buf *linker_optimization = nullptr;453 Buf *linker_optimization = nullptr;
453 OptionalBool linker_gc_sections = OptionalBoolNull;454 OptionalBool linker_gc_sections = OptionalBoolNull;
454 OptionalBool linker_allow_shlib_undefined = OptionalBoolNull;455 OptionalBool linker_allow_shlib_undefined = OptionalBoolNull;
456 OptionalBool linker_bind_global_refs_locally = OptionalBoolNull;
455 bool linker_z_nodelete = false;457 bool linker_z_nodelete = false;
456 bool linker_z_defs = false;458 bool linker_z_defs = false;
457 size_t stack_size_override = 0;459 size_t stack_size_override = 0;
...@@ -842,6 +844,8 @@ static int main0(int argc, char **argv) {...@@ -842,6 +844,8 @@ static int main0(int argc, char **argv) {
842 buf_eql_str(arg, "-no-allow-shlib-undefined"))844 buf_eql_str(arg, "-no-allow-shlib-undefined"))
843 {845 {
844 linker_allow_shlib_undefined = OptionalBoolFalse;846 linker_allow_shlib_undefined = OptionalBoolFalse;
847 } else if (buf_eql_str(arg, "-Bsymbolic")) {
848 linker_bind_global_refs_locally = OptionalBoolTrue;
845 } else if (buf_eql_str(arg, "-z")) {849 } else if (buf_eql_str(arg, "-z")) {
846 i += 1;850 i += 1;
847 if (i >= linker_args.length) {851 if (i >= linker_args.length) {
...@@ -1013,6 +1017,8 @@ static int main0(int argc, char **argv) {...@@ -1013,6 +1017,8 @@ static int main0(int argc, char **argv) {
1013 want_single_threaded = true;;1017 want_single_threaded = true;;
1014 } else if (strcmp(arg, "--bundle-compiler-rt") == 0) {1018 } else if (strcmp(arg, "--bundle-compiler-rt") == 0) {
1015 bundle_compiler_rt = true;1019 bundle_compiler_rt = true;
1020 } else if (strcmp(arg, "-Bsymbolic") == 0) {
1021 linker_bind_global_refs_locally = OptionalBoolTrue;
1016 } else if (strcmp(arg, "--test-cmd-bin") == 0) {1022 } else if (strcmp(arg, "--test-cmd-bin") == 0) {
1017 test_exec_args.append(nullptr);1023 test_exec_args.append(nullptr);
1018 } else if (arg[1] == 'D' && arg[2] != 0) {1024 } else if (arg[1] == 'D' && arg[2] != 0) {
...@@ -1609,6 +1615,7 @@ static int main0(int argc, char **argv) {...@@ -1609,6 +1615,7 @@ static int main0(int argc, char **argv) {
1609 g->linker_optimization = linker_optimization;1615 g->linker_optimization = linker_optimization;
1610 g->linker_gc_sections = linker_gc_sections;1616 g->linker_gc_sections = linker_gc_sections;
1611 g->linker_allow_shlib_undefined = linker_allow_shlib_undefined;1617 g->linker_allow_shlib_undefined = linker_allow_shlib_undefined;
1618 g->linker_bind_global_refs_locally = linker_bind_global_refs_locally;
1612 g->linker_z_nodelete = linker_z_nodelete;1619 g->linker_z_nodelete = linker_z_nodelete;
1613 g->linker_z_defs = linker_z_defs;1620 g->linker_z_defs = linker_z_defs;
1614 g->stack_size_override = stack_size_override;1621 g->stack_size_override = stack_size_override;