Added -z argument.

This commit is contained in:
Christoffer Lerno
2021-07-15 11:48:06 +02:00
parent d93382d858
commit cb9bcfe42a
4 changed files with 32 additions and 1 deletions

View File

@@ -90,7 +90,9 @@ static void usage(void)
OUTPUT(" -fpic - Generate position independent (PIC) code if suitable.");
OUTPUT(" -fno-pic - Do not generate position independent code.");
OUTPUT(" -fPIC - Always generate position independent (PIC) code.");
OUTPUT(" -fno-PIC - generate position independent (PIC) code.");
OUTPUT(" -fno-PIC - Generate position independent (PIC) code.");
OUTPUT("");
OUTPUT(" -z <argument> - Send the <argument> as a parameter to the linker.");
}
@@ -108,6 +110,16 @@ static const char* check_dir(const char *path)
return path;
}
static const char* check_file(const char *file_path)
{
FILE *file = fopen(file_path, "rb");
if (file == NULL)
{
error_exit("Could not open file \"%s\".\n", file_path);
}
return file_path;
}
static inline bool at_end()
{
return arg_index == arg_count - 1;
@@ -315,6 +327,10 @@ static void parse_option(BuildOptions *options)
FAIL_WITH_ERR("Unknown argument -%s.", &current_arg[1]);
case 'h':
break;
case 'z':
if (at_end()) error_exit("error: -z needs a value");
options->linker_args[options->linker_arg_count++] = next_arg();
return;
case 'O':
if (options->optimization_setting_override != OPT_SETTING_NOT_SET)
{

View File

@@ -167,8 +167,10 @@ typedef enum
typedef struct BuildOptions_
{
const char* lib_dir[MAX_LIB_DIRS];
const char* linker_args[MAX_LIB_DIRS];
const char* std_lib_dir;
int lib_count;
int linker_arg_count;
int build_threads;
const char** files;
const char* project_name;
@@ -210,6 +212,7 @@ typedef struct
const char **sources;
const char **libraries;
const char *cpu;
const char **link_args;
bool run_after_compile : 1;
bool test_output : 1;
bool output_headers : 1;

View File

@@ -85,6 +85,10 @@ static void update_build_target_from_options(BuildTarget *target, BuildOptions *
if (options->pie != PIE_DEFAULT) target->pie = options->pie;
if (options->pic != PIC_DEFAULT) target->pic = options->pic;
for (int i = 0; i < options->linker_arg_count; i++)
{
vec_add(target->link_args, options->linker_args[i]);
}
target->emit_llvm = options->emit_llvm;
switch (options->compile_option)
{

View File

@@ -66,6 +66,10 @@ static bool link_exe(const char *output_file, const char **files_to_link, unsign
const char **args = NULL;
vec_add(args, "-o");
vec_add(args, output_file);
VECEACH(active_target.link_args, i)
{
vec_add(args, active_target.link_args[i]);
}
const char *error = NULL;
switch (platform_target.os)
@@ -235,6 +239,10 @@ void platform_linker(const char *output_file, const char **files, unsigned file_
const char **parts = NULL;
vec_add(parts, "cc");
vec_add(parts, "-lm");
VECEACH(active_target.link_args, i)
{
vec_add(parts, active_target.link_args[i]);
}
switch (platform_target.pie)
{
case PIE_DEFAULT: