Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile with --pic on Linux if linker is gcc #1819

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 1 addition & 23 deletions src/libponyc/codegen/genexe.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,6 @@ LLVMValueRef gen_main(compile_t* c, reach_type_t* t_main, reach_type_t* t_env)
return func;
}

#if defined(PLATFORM_IS_LINUX) || defined(PLATFORM_IS_FREEBSD)
static const char* env_cc_or_pony_compiler(bool* out_fallback_linker)
{
const char* cc = getenv("CC");
if(cc == NULL)
{
*out_fallback_linker = true;
return PONY_COMPILER;
}
return cc;
}
#endif

static bool link_exe(compile_t* c, ast_t* program,
const char* file_o)
{
Expand Down Expand Up @@ -249,16 +236,7 @@ static bool link_exe(compile_t* c, ast_t* program,
const char* lib_args = program_lib_args(program);

const char* arch = c->opt->link_arch != NULL ? c->opt->link_arch : PONY_ARCH;
bool fallback_linker = false;
const char* linker = c->opt->linker != NULL ? c->opt->linker :
env_cc_or_pony_compiler(&fallback_linker);

if((c->opt->verbosity >= VERBOSITY_MINIMAL) && fallback_linker)
{
fprintf(stderr,
"Warning: environment variable $CC undefined, using %s as the linker\n",
PONY_COMPILER);
}
const char* mcx16_arg = target_is_ilp32(c->opt->triple) ? "" : "-mcx16";
const char* fuseld = target_is_linux(c->opt->triple) ? "-fuse-ld=gold" : "";
const char* ldl = target_is_linux(c->opt->triple) ? "-ldl" : "";
Expand All @@ -278,7 +256,7 @@ static bool link_exe(compile_t* c, ast_t* program,
"-flto -fuse-linker-plugin "
#endif
"%s %s %s %s -lpthread %s -lm %s",
linker, file_exe, arch, mcx16_arg, fuseld, file_o, lib_args, ponyrt, ldl,
c->opt->linker, file_exe, arch, mcx16_arg, fuseld, file_o, lib_args, ponyrt, ldl,
export
);

Expand Down
24 changes: 24 additions & 0 deletions src/ponyc/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,30 @@ int main(int argc, char* argv[])
opt.strip_debug = true;
#endif

#if defined(PLATFORM_IS_LINUX) || defined(PLATFORM_IS_FREEBSD)
if(opt.linker == NULL)
{
char* cc = getenv("CC");
if(cc == NULL)
{
if(opt.verbosity >= VERBOSITY_MINIMAL)
{
fprintf(stderr,
"\nWarning: environment variable $CC undefined, "
"using %s as the linker\n\n",
PONY_COMPILER);
}

opt.linker = PONY_COMPILER;
} else {
opt.linker = cc;
}
}

if(strcmp(opt.linker, "gcc") == 0 || strcmp(opt.linker, "cc") == 0)
opt.pic = true;
#endif

if(!ok)
{
errors_print(opt.check.errors);
Expand Down