add --eh-frame-hdr conditionally

This commit is contained in:
David Cao
2020-01-03 21:28:58 -08:00
committed by Andrew Kelley
parent 599213463d
commit 8e57dd57ca
8 changed files with 32 additions and 2 deletions

View File

@@ -2131,6 +2131,7 @@ struct CodeGen {
bool have_winmain_crt_startup;
bool have_dllmain_crt_startup;
bool have_err_ret_tracing;
bool link_eh_frame_hdr;
bool c_want_stdint;
bool c_want_stdbool;
bool verbose_tokenize;

View File

@@ -8629,6 +8629,7 @@ static Error define_builtin_compile_vars(CodeGen *g) {
cache_bool(&cache_hash, g->have_err_ret_tracing);
cache_bool(&cache_hash, g->libc_link_lib != nullptr);
cache_bool(&cache_hash, g->valgrind_support);
cache_bool(&cache_hash, g->link_eh_frame_hdr);
cache_int(&cache_hash, detect_subsystem(g));
Buf digest = BUF_INIT;
@@ -9510,6 +9511,7 @@ Error create_c_object_cache(CodeGen *g, CacheHash **out_cache_hash, bool verbose
cache_int(cache_hash, g->build_mode);
cache_bool(cache_hash, g->have_pic);
cache_bool(cache_hash, g->have_sanitize_c);
cache_bool(cache_hash, g->link_eh_frame_hdr);
cache_bool(cache_hash, want_valgrind_support(g));
cache_bool(cache_hash, g->function_sections);
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) {
cache_buf_opt(ch, g->test_filter);
cache_buf_opt(ch, g->test_name_prefix);
}
cache_bool(ch, g->link_eh_frame_hdr);
cache_bool(ch, g->is_single_threaded);
cache_bool(ch, g->linker_rdynamic);
cache_bool(ch, g->each_lib_rpath);

View File

@@ -1647,7 +1647,9 @@ static void construct_linker_job_elf(LinkJob *lj) {
lj->args.append("--gc-sections");
}
lj->args.append("--eh-frame-hdr");
if (g->link_eh_frame_hdr) {
lj->args.append("--eh-frame-hdr");
}
lj->args.append("-m");
lj->args.append(getLDMOption(g->zig_target));

View File

@@ -55,6 +55,7 @@ static int print_full_usage(const char *arg0, FILE *file, int return_code) {
" --color [auto|off|on] enable or disable colored error messages\n"
" --disable-gen-h do not generate a C header file (.h)\n"
" --disable-valgrind omit valgrind client requests in debug builds\n"
" --eh-frame-hdr enable C++ exception handling by passing --eh-frame-hdr to linker\n"
" --enable-valgrind include valgrind client requests release builds\n"
" -fstack-check enable stack probing in unsafe builds\n"
" -fno-stack-check disable stack probing in safe builds\n"
@@ -477,6 +478,7 @@ int main(int argc, char **argv) {
bool verbose_llvm_ir = false;
bool verbose_cimport = false;
bool verbose_cc = false;
bool link_eh_frame_hdr = false;
ErrColor color = ErrColorAuto;
CacheOpt enable_cache = CacheOptAuto;
Buf *dynamic_linker = nullptr;
@@ -715,6 +717,8 @@ int main(int argc, char **argv) {
valgrind_support = ValgrindSupportEnabled;
} else if (strcmp(arg, "--disable-valgrind") == 0) {
valgrind_support = ValgrindSupportDisabled;
} else if (strcmp(arg, "--eh-frame-hdr") == 0) {
link_eh_frame_hdr = true;
} else if (strcmp(arg, "-fPIC") == 0) {
want_pic = WantPICEnabled;
} else if (strcmp(arg, "-fno-PIC") == 0) {
@@ -1191,6 +1195,7 @@ int main(int argc, char **argv) {
override_lib_dir, libc, cache_dir_buf, cmd == CmdTest, root_progress_node);
if (llvm_argv.length >= 2) codegen_set_llvm_argv(g, llvm_argv.items + 1, llvm_argv.length - 2);
g->valgrind_support = valgrind_support;
g->link_eh_frame_hdr = link_eh_frame_hdr;
g->want_pic = want_pic;
g->want_stack_check = want_stack_check;
g->want_sanitize_c = want_sanitize_c;