From cd288b9cb188f689299d9a8dc1ee52a6be8637c0 Mon Sep 17 00:00:00 2001 From: Dipin Hora Date: Sun, 28 Jul 2019 01:00:04 +0000 Subject: [PATCH 1/3] Ensure that `-latomic` comes after `-static` to fix static linking --- src/libponyc/codegen/genexe.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libponyc/codegen/genexe.c b/src/libponyc/codegen/genexe.c index 7c5044b532..cd351afb43 100644 --- a/src/libponyc/codegen/genexe.c +++ b/src/libponyc/codegen/genexe.c @@ -389,12 +389,12 @@ static bool link_exe(compile_t* c, ast_t* program, #endif #ifdef PLATFORM_IS_OPENBSD // On OpenBSD, the unwind symbols are contained within libc++abi. - "%s %s %s %s %s -lpthread %s %s %s -lm -lc++abi %s %s", + "%s %s %s %s -lpthread %s %s %s -lm -lc++abi %s %s %s", #else - "%s %s %s %s %s -lpthread %s %s %s -lm %s %s", + "%s %s %s %s -lpthread %s %s %s -lm %s %s %s", #endif - linker, file_exe, arch, mcx16_arg, atomic, staticbin, fuseld, file_o, - lib_args, dtrace_args, ponyrt, ldl, lexecinfo, sanitizer_arg + linker, file_exe, arch, mcx16_arg, staticbin, fuseld, file_o, + lib_args, dtrace_args, ponyrt, ldl, lexecinfo, atomic, sanitizer_arg ); if(c->opt->verbosity >= VERBOSITY_TOOL_INFO) From c09bc778118db6bdd26faa504a18cb00fda01223 Mon Sep 17 00:00:00 2001 From: Dipin Hora Date: Sun, 28 Jul 2019 01:29:29 +0000 Subject: [PATCH 2/3] Allow overriding `-fuse-ld` command for linking --- src/libponyc/codegen/genexe.c | 12 +++++++----- src/libponyc/options/options.c | 5 +++++ src/libponyc/pass/pass.h | 1 + 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/libponyc/codegen/genexe.c b/src/libponyc/codegen/genexe.c index cd351afb43..4544cf480a 100644 --- a/src/libponyc/codegen/genexe.c +++ b/src/libponyc/codegen/genexe.c @@ -343,7 +343,9 @@ static bool link_exe(compile_t* c, ast_t* program, env_cc_or_pony_compiler(&fallback_linker); const char* mcx16_arg = (target_is_lp64(c->opt->triple) && target_is_x86(c->opt->triple)) ? "-mcx16" : ""; - const char* fuseld = target_is_linux(c->opt->triple) ? "-fuse-ld=gold" : ""; + const char* fuseldcmd = c->opt->link_ldcmd != NULL ? c->opt->link_ldcmd : + (target_is_linux(c->opt->triple) ? "gold" : ""); + const char* fuseld = strlen(fuseldcmd) ? "-fuse-ld=" : ""; const char* ldl = target_is_linux(c->opt->triple) ? "-ldl" : ""; const char* atomic = target_is_linux(c->opt->triple) ? "-latomic" : ""; const char* staticbin = c->opt->staticbin ? "-static" : ""; @@ -371,7 +373,7 @@ static bool link_exe(compile_t* c, ast_t* program, size_t ld_len = 512 + strlen(file_exe) + strlen(file_o) + strlen(lib_args) + strlen(arch) + strlen(mcx16_arg) + strlen(fuseld) + strlen(ldl) + strlen(atomic) + strlen(staticbin) - + strlen(dtrace_args) + strlen(lexecinfo) + + strlen(dtrace_args) + strlen(lexecinfo) + strlen(fuseldcmd) + strlen(sanitizer_arg); char* ld_cmd = (char*)ponyint_pool_alloc_size(ld_len); @@ -389,11 +391,11 @@ static bool link_exe(compile_t* c, ast_t* program, #endif #ifdef PLATFORM_IS_OPENBSD // On OpenBSD, the unwind symbols are contained within libc++abi. - "%s %s %s %s -lpthread %s %s %s -lm -lc++abi %s %s %s", + "%s %s%s %s %s -lpthread %s %s %s -lm -lc++abi %s %s %s", #else - "%s %s %s %s -lpthread %s %s %s -lm %s %s %s", + "%s %s%s %s %s -lpthread %s %s %s -lm %s %s %s", #endif - linker, file_exe, arch, mcx16_arg, staticbin, fuseld, file_o, + linker, file_exe, arch, mcx16_arg, staticbin, fuseld, fuseldcmd, file_o, lib_args, dtrace_args, ponyrt, ldl, lexecinfo, atomic, sanitizer_arg ); diff --git a/src/libponyc/options/options.c b/src/libponyc/options/options.c index da1a34259a..e36c310741 100644 --- a/src/libponyc/options/options.c +++ b/src/libponyc/options/options.c @@ -44,6 +44,7 @@ enum OPT_STATS, OPT_LINK_ARCH, OPT_LINKER, + OPT_LINK_LDCMD, OPT_PLUGIN, OPT_VERBOSE, @@ -90,6 +91,7 @@ static opt_arg_t std_args[] = {"stats", '\0', OPT_ARG_NONE, OPT_STATS}, {"link-arch", '\0', OPT_ARG_REQUIRED, OPT_LINK_ARCH}, {"linker", '\0', OPT_ARG_REQUIRED, OPT_LINKER}, + {"link-ldcmd", '\0', OPT_ARG_REQUIRED, OPT_LINK_LDCMD}, {"plugin", '\0', OPT_ARG_REQUIRED, OPT_PLUGIN}, {"verbose", 'V', OPT_ARG_REQUIRED, OPT_VERBOSE}, @@ -159,6 +161,8 @@ static void usage(void) " =name Default is the host architecture.\n" " --linker Set the linker command to use.\n" " =name Default is the compiler used to compile ponyc.\n" + " --link-ldcmd Set the ld command to use.\n" + " =name Default is `gold` on linux and system default otherwise.\n" " --plugin Use the specified plugin(s).\n" " =name\n" " --define, -D Set a compile time definition.\n" @@ -341,6 +345,7 @@ ponyc_opt_process_t ponyc_opt_process(opt_state_t* s, pass_opt_t* opt, case OPT_STATS: opt->print_stats = true; break; case OPT_LINK_ARCH: opt->link_arch = s->arg_val; break; case OPT_LINKER: opt->linker = s->arg_val; break; + case OPT_LINK_LDCMD: opt->link_ldcmd = s->arg_val; break; case OPT_PLUGIN: if(!plugin_load(opt, s->arg_val)) { diff --git a/src/libponyc/pass/pass.h b/src/libponyc/pass/pass.h index 266b54abce..92726ea425 100644 --- a/src/libponyc/pass/pass.h +++ b/src/libponyc/pass/pass.h @@ -296,6 +296,7 @@ typedef struct pass_opt_t const char* bin_name; char* link_arch; char* linker; + char* link_ldcmd; char* triple; char* cpu; From 22a59bbfce5b3cc3104f96539b087adbc5e7a6f4 Mon Sep 17 00:00:00 2001 From: Dipin Hora Date: Sun, 28 Jul 2019 02:16:29 +0000 Subject: [PATCH 3/3] Add changelog entry --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b316e57ca3..ca050c2b92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,11 @@ All notable changes to the Pony compiler and standard library will be documented ### Fixed +- Fix static linking issue by changing the link order ([PR #3259](https://github.com/ponylang/ponyc/pull/3259)) ### Added +- Add `--link-ldcmd` command line argument for overriding the `ld` command used for linking ([PR #3259](https://github.com/ponylang/ponyc/pull/3259)) ### Changed