mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
- Fix problem where crt1 was linked for dynamic libraries on Linux and BSD. #1710
This commit is contained in:
committed by
Christoffer Lerno
parent
e453e6f9ca
commit
0ff52311c3
@@ -12,11 +12,11 @@ const char *quote_arg = "\"";
|
||||
const char *concat_arg = ":";
|
||||
const char *concat_quote_arg = "+";
|
||||
const char *concat_file_arg = "/";
|
||||
#define add_quote_arg(arg_) vec_add(*args_ref, quote_arg); vec_add(*args_ref, (arg_))
|
||||
#define add_quote_arg(arg_) do { vec_add(*args_ref, quote_arg); vec_add(*args_ref, (arg_)); } while(0)
|
||||
#define add_plain_arg(arg_) vec_add(*args_ref, (arg_))
|
||||
#define add_concat_file_arg(arg_, arg2_) vec_add(*args_ref, concat_file_arg); vec_add(*args_ref, (arg_)); vec_add(*args_ref, (arg2_))
|
||||
#define add_concat_arg(arg_, arg2_) vec_add(*args_ref, concat_arg); vec_add(*args_ref, (arg_)); vec_add(*args_ref, (arg2_))
|
||||
#define add_concat_quote_arg(arg_, arg2_) vec_add(*args_ref, concat_quote_arg); vec_add(*args_ref, (arg_)); vec_add(*args_ref, (arg2_))
|
||||
#define add_concat_file_arg(arg_, arg2_) do { vec_add(*args_ref, concat_file_arg); vec_add(*args_ref, (arg_)); vec_add(*args_ref, (arg2_)); } while(0)
|
||||
#define add_concat_arg(arg_, arg2_) do { vec_add(*args_ref, concat_arg); vec_add(*args_ref, (arg_)); vec_add(*args_ref, (arg2_)); } while(0)
|
||||
#define add_concat_quote_arg(arg_, arg2_) do { vec_add(*args_ref, concat_quote_arg); vec_add(*args_ref, (arg_)); vec_add(*args_ref, (arg2_)); } while(0)
|
||||
|
||||
static char *assemble_linker_command(const char **args, bool extra_quote);
|
||||
static unsigned assemble_link_arguments(const char **arguments, unsigned len);
|
||||
@@ -331,7 +331,7 @@ static const char *find_linux_crt_begin(void)
|
||||
return path;
|
||||
}
|
||||
|
||||
static void linker_setup_linux(const char ***args_ref, Linker linker_type)
|
||||
static void linker_setup_linux(const char ***args_ref, Linker linker_type, bool is_dylib)
|
||||
{
|
||||
linking_add_link(&compiler.linking, "dl");
|
||||
if (linker_type == LINKER_CC)
|
||||
@@ -374,16 +374,16 @@ static void linker_setup_linux(const char ***args_ref, Linker linker_type)
|
||||
}
|
||||
if (is_pie_pic(compiler.platform.reloc_model))
|
||||
{
|
||||
add_concat_file_arg(crt_dir, "Scrt1.o");
|
||||
add_concat_file_arg(crt_begin_dir, "crtbeginS.o");
|
||||
add_concat_file_arg(crt_dir, "crti.o");
|
||||
if (!is_dylib) add_concat_file_arg(crt_dir, "Scrt1.o");
|
||||
add_concat_file_arg(crt_begin_dir, "crtbeginS.o");
|
||||
add_concat_file_arg(crt_begin_dir, "crtendS.o");
|
||||
}
|
||||
else
|
||||
{
|
||||
add_concat_file_arg(crt_dir, "crt1.o");
|
||||
add_concat_file_arg(crt_begin_dir, "crtbegin.o");
|
||||
add_concat_file_arg(crt_dir, "crti.o");
|
||||
if (!is_dylib) add_concat_file_arg(crt_dir, "crt1.o");
|
||||
add_concat_file_arg(crt_begin_dir, "crtbegin.o");
|
||||
add_concat_file_arg(crt_begin_dir, "crtend.o");
|
||||
}
|
||||
add_concat_file_arg(crt_dir, "crtn.o");
|
||||
@@ -399,7 +399,7 @@ static void linker_setup_linux(const char ***args_ref, Linker linker_type)
|
||||
add_plain_arg(ld_target(compiler.platform.arch));
|
||||
}
|
||||
|
||||
static void linker_setup_freebsd(const char ***args_ref, Linker linker_type)
|
||||
static void linker_setup_freebsd(const char ***args_ref, Linker linker_type, bool is_dylib)
|
||||
{
|
||||
if (linker_type == LINKER_CC) {
|
||||
linking_add_link(&compiler.linking, "m");
|
||||
@@ -421,20 +421,19 @@ static void linker_setup_freebsd(const char ***args_ref, Linker linker_type)
|
||||
{
|
||||
add_plain_arg("--gc-sections");
|
||||
}
|
||||
|
||||
if (is_pie_pic(compiler.platform.reloc_model))
|
||||
{
|
||||
add_plain_arg("-pie");
|
||||
add_concat_file_arg(crt_dir, "Scrt1.o");
|
||||
add_concat_file_arg(crt_dir, "crtbeginS.o");
|
||||
add_concat_file_arg(crt_dir, "crti.o");
|
||||
if (!is_dylib) add_concat_file_arg(crt_dir, "Scrt1.o");
|
||||
add_concat_file_arg(crt_dir, "crtbeginS.o");
|
||||
add_concat_file_arg(crt_dir, "crtendS.o");
|
||||
}
|
||||
else
|
||||
{
|
||||
add_concat_file_arg(crt_dir, "crt1.o");
|
||||
add_concat_file_arg(crt_dir, "crtbegin.o");
|
||||
add_concat_file_arg(crt_dir, "crti.o");
|
||||
if (!is_dylib) add_concat_file_arg(crt_dir, "crt1.o");
|
||||
add_concat_file_arg(crt_dir, "crtbegin.o");
|
||||
add_concat_file_arg(crt_dir, "crtend.o");
|
||||
}
|
||||
add_concat_file_arg(crt_dir, "crtn.o");
|
||||
@@ -546,10 +545,10 @@ static bool linker_setup(const char ***args_ref, const char **files_to_link, uns
|
||||
case OS_TYPE_FREE_BSD:
|
||||
case OS_TYPE_OPENBSD:
|
||||
case OS_TYPE_NETBSD:
|
||||
linker_setup_freebsd(args_ref, linker_type);
|
||||
linker_setup_freebsd(args_ref, linker_type, is_dylib);
|
||||
break;
|
||||
case OS_TYPE_LINUX:
|
||||
linker_setup_linux(args_ref, linker_type);
|
||||
linker_setup_linux(args_ref, linker_type, is_dylib);
|
||||
break;
|
||||
case OS_TYPE_UNKNOWN:
|
||||
if (link_libc())
|
||||
|
||||
Reference in New Issue
Block a user