authorgravatar for david@cao.shDavid Cao <david@cao.sh> 2020-01-03 21:28:58-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-07 15:58:40-05:00
log8e57dd57cab68b469fcdfd4792ceb5ca09220924
tree82d8ba830f2dc166646091c85821f5f6b7818ecc
parent599213463d51bf3946df53e04091f6cda3d8ee0e
signature Commit is signed but in an unrecognized format.

add --eh-frame-hdr conditionally


8 files changed, 32 insertions(+), 2 deletions(-)

lib/std/build.zig+9
......@@ -40,6 +40,7 @@ pub const Builder = struct {
4040 verbose_ir: bool,
4141 verbose_llvm_ir: bool,
4242 verbose_cimport: bool,
43 link_eh_frame_hdr: bool,
4344 invalid_user_input: bool,
4445 zig_exe: []const u8,
4546 default_step: *Step,
......@@ -136,6 +137,7 @@ pub const Builder = struct {
136137 .verbose_ir = false,
137138 .verbose_llvm_ir = false,
138139 .verbose_cimport = false,
140 .link_eh_frame_hdr = false,
139141 .invalid_user_input = false,
140142 .allocator = allocator,
141143 .native_system_lib_paths = ArrayList([]const u8).init(allocator),
......@@ -1175,6 +1177,8 @@ pub const LibExeObjStep = struct {
11751177
11761178 valgrind_support: ?bool = null,
11771179
1180 link_eh_frame_hdr: bool = false,
1181
11781182 /// Uses system Wine installation to run cross compiled Windows build artifacts.
11791183 enable_wine: bool = false,
11801184
......@@ -1623,6 +1627,10 @@ pub const LibExeObjStep = struct {
16231627 self.verbose_cc = value;
16241628 }
16251629
1630 pub fn setLinkEhFrameHdr(self: *LibExeObjStep, value: bool) void {
1631 self.link_eh_frame_hdr = value;
1632 }
1633
16261634 pub fn setBuildMode(self: *LibExeObjStep, mode: builtin.Mode) void {
16271635 self.build_mode = mode;
16281636 }
......@@ -1908,6 +1916,7 @@ pub const LibExeObjStep = struct {
19081916 if (builder.verbose_llvm_ir) zig_args.append("--verbose-llvm-ir") catch unreachable;
19091917 if (builder.verbose_link or self.verbose_link) zig_args.append("--verbose-link") catch unreachable;
19101918 if (builder.verbose_cc or self.verbose_cc) zig_args.append("--verbose-cc") catch unreachable;
1919 if (builder.link_eh_frame_hdr or self.link_eh_frame_hdr) zig_args.append("--eh-frame-hdr") catch unreachable;
19111920
19121921 if (self.strip) {
19131922 zig_args.append("--strip") catch unreachable;
src-self-hosted/compilation.zig+2
......@@ -170,6 +170,8 @@ pub const Compilation = struct {
170170 verbose_llvm_ir: bool = false,
171171 verbose_link: bool = false,
172172
173 link_eh_frame_hdr: bool = false,
174
173175 darwin_version_min: DarwinVersionMin = .None,
174176
175177 test_filters: []const []const u8 = &[_][]const u8{},
src-self-hosted/link.zig+3-1
......@@ -144,7 +144,9 @@ fn constructLinkerArgsElf(ctx: *Context) !void {
144144 // lj->args.append(g->linker_script);
145145 //}
146146 try ctx.args.append("--gc-sections");
147 try ctx.args.append("--eh-frame-hdr");
147 if (ctx.comp.link_eh_frame_hdr) {
148 try ctx.args.append("--eh-frame-hdr");
149 }
148150
149151 //lj->args.append("-m");
150152 //lj->args.append(getLDMOption(&g->zig_target));
src-self-hosted/main.zig+6
......@@ -154,6 +154,7 @@ const usage_build_generic =
154154 \\ --static Output will be statically linked
155155 \\ --strip Exclude debug symbols
156156 \\ -target [name] <arch><sub>-<os>-<abi> see the targets command
157 \\ --eh-frame-hdr enable C++ exception handling by passing --eh-frame-hdr to linker
157158 \\ --verbose-tokenize Turn on compiler debug output for tokenization
158159 \\ --verbose-ast-tree Turn on compiler debug output for parsing into an AST (tree view)
159160 \\ --verbose-ast-fmt Turn on compiler debug output for parsing into an AST (render source)
......@@ -207,6 +208,7 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
207208 var verbose_llvm_ir = false;
208209 var verbose_cimport = false;
209210 var linker_rdynamic = false;
211 var link_eh_frame_hdr = false;
210212 var macosx_version_min: ?[]const u8 = null;
211213 var ios_version_min: ?[]const u8 = null;
212214
......@@ -369,6 +371,8 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
369371 verbose_ir = true;
370372 } else if (mem.eql(u8, arg, "--verbose-llvm-ir")) {
371373 verbose_llvm_ir = true;
374 } else if (mem.eql(u8, arg, "--eh-frame-hdr")) {
375 link_eh_frame_hdr = true;
372376 } else if (mem.eql(u8, arg, "--verbose-cimport")) {
373377 verbose_cimport = true;
374378 } else if (mem.eql(u8, arg, "-rdynamic")) {
......@@ -498,6 +502,8 @@ fn buildOutputType(allocator: *Allocator, args: []const []const u8, out_type: Co
498502 comp.verbose_llvm_ir = verbose_llvm_ir;
499503 comp.verbose_cimport = verbose_cimport;
500504
505 comp.link_eh_frame_hdr = link_eh_frame_hdr;
506
501507 comp.err_color = color;
502508
503509 comp.linker_rdynamic = linker_rdynamic;
src/all_types.hpp+1
......@@ -2131,6 +2131,7 @@ struct CodeGen {
21312131 bool have_winmain_crt_startup;
21322132 bool have_dllmain_crt_startup;
21332133 bool have_err_ret_tracing;
2134 bool link_eh_frame_hdr;
21342135 bool c_want_stdint;
21352136 bool c_want_stdbool;
21362137 bool verbose_tokenize;
src/codegen.cpp+3
......@@ -8629,6 +8629,7 @@ static Error define_builtin_compile_vars(CodeGen *g) {
86298629 cache_bool(&cache_hash, g->have_err_ret_tracing);
86308630 cache_bool(&cache_hash, g->libc_link_lib != nullptr);
86318631 cache_bool(&cache_hash, g->valgrind_support);
8632 cache_bool(&cache_hash, g->link_eh_frame_hdr);
86328633 cache_int(&cache_hash, detect_subsystem(g));
86338634
86348635 Buf digest = BUF_INIT;
......@@ -9510,6 +9511,7 @@ Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose
95109511 cache_int(cache_hash, g->build_mode);
95119512 cache_bool(cache_hash, g->have_pic);
95129513 cache_bool(cache_hash, g->have_sanitize_c);
9514 cache_bool(cache_hash, g->link_eh_frame_hdr);
95139515 cache_bool(cache_hash, want_valgrind_support(g));
95149516 cache_bool(cache_hash, g->function_sections);
95159517 for (size_t arg_i = 0; arg_i < g->clang_argv_len; arg_i += 1) {
......@@ -10279,6 +10281,7 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
1027910281 cache_buf_opt(ch, g->test_filter);
1028010282 cache_buf_opt(ch, g->test_name_prefix);
1028110283 }
10284 cache_bool(ch, g->link_eh_frame_hdr);
1028210285 cache_bool(ch, g->is_single_threaded);
1028310286 cache_bool(ch, g->linker_rdynamic);
1028410287 cache_bool(ch, g->each_lib_rpath);
src/link.cpp+3-1
......@@ -1647,7 +1647,9 @@ static void construct_linker_job_elf(LinkJob *lj) {
16471647 lj->args.append("--gc-sections");
16481648 }
16491649
1650 lj->args.append("--eh-frame-hdr");
1650 if (g->link_eh_frame_hdr) {
1651 lj->args.append("--eh-frame-hdr");
1652 }
16511653
16521654 lj->args.append("-m");
16531655 lj->args.append(getLDMOption(g->zig_target));
src/main.cpp+5
......@@ -55,6 +55,7 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {
5555 " --color [auto|off|on] enable or disable colored error messages\n"
5656 " --disable-gen-h do not generate a C header file (.h)\n"
5757 " --disable-valgrind omit valgrind client requests in debug builds\n"
58 " --eh-frame-hdr enable C++ exception handling by passing --eh-frame-hdr to linker\n"
5859 " --enable-valgrind include valgrind client requests release builds\n"
5960 " -fstack-check enable stack probing in unsafe builds\n"
6061 " -fno-stack-check disable stack probing in safe builds\n"
......@@ -477,6 +478,7 @@ int main(int argc, char **argv) {
477478 bool verbose_llvm_ir = false;
478479 bool verbose_cimport = false;
479480 bool verbose_cc = false;
481 bool link_eh_frame_hdr = false;
480482 ErrColor color = ErrColorAuto;
481483 CacheOpt enable_cache = CacheOptAuto;
482484 Buf *dynamic_linker = nullptr;
......@@ -715,6 +717,8 @@ int main(int argc, char **argv) {
715717 valgrind_support = ValgrindSupportEnabled;
716718 } else if (strcmp(arg, "--disable-valgrind") == 0) {
717719 valgrind_support = ValgrindSupportDisabled;
720 } else if (strcmp(arg, "--eh-frame-hdr") == 0) {
721 link_eh_frame_hdr = true;
718722 } else if (strcmp(arg, "-fPIC") == 0) {
719723 want_pic = WantPICEnabled;
720724 } else if (strcmp(arg, "-fno-PIC") == 0) {
......@@ -1191,6 +1195,7 @@ int main(int argc, char **argv) {
11911195 override_lib_dir, libc, cache_dir_buf, cmd == CmdTest, root_progress_node);
11921196 if (llvm_argv.length >= 2) codegen_set_llvm_argv(g, llvm_argv.items + 1, llvm_argv.length - 2);
11931197 g->valgrind_support = valgrind_support;
1198 g->link_eh_frame_hdr = link_eh_frame_hdr;
11941199 g->want_pic = want_pic;
11951200 g->want_stack_check = want_stack_check;
11961201 g->want_sanitize_c = want_sanitize_c;