Compatible with ld.bfd, gold, lld and mold. Also, document existing behaviour of LD_SO environment variable
Unified · Split
| @@ -1428,6 +1428,13 @@ static int tcc_set_linker(TCCState *s, const char *option) · 1427 unmodified lines | |||
| 1428 | s->rdynamic = 1; | 1428 | s->rdynamic = 1; |
| 1429 | } else if (link_option(option, "rpath=", &p)) { | 1429 | } else if (link_option(option, "rpath=", &p)) { |
| 1430 | copy_linker_arg(&s->rpath, p, ':'); | 1430 | copy_linker_arg(&s->rpath, p, ':'); |
| 1431 | } else if (link_option(option, "dynamic-linker=", &p) | ||
| 1432 | || link_option(option, "I=", &p)) { | ||
| 1433 | copy_linker_arg(&s->elfint, p, 0); | ||
| 1434 | } else if (strncmp("-I/", option, 3) == 0 | ||
| 1435 | || strncmp("-I.", option, 3) == 0) { | ||
| 1436 | p = option; | ||
| 1437 | copy_linker_arg(&s->elfint, option + 2, 0); | ||
| 1431 | } else if (link_option(option, "enable-new-dtags", &p)) { | 1438 | } else if (link_option(option, "enable-new-dtags", &p)) { |
| 1432 | s->enable_new_dtags = 1; | 1439 | s->enable_new_dtags = 1; |
| 1433 | } else if (link_option(option, "section-alignment=", &p)) { | 1440 | } else if (link_option(option, "section-alignment=", &p)) { |
| @@ -360,6 +360,11 @@ Generate an object file combining all input files. · 359 unmodified lines | |||
| 360 | @item -Wl,-rpath=path | 360 | @item -Wl,-rpath=path |
| 361 | Put custom search path for dynamic libraries into executable. | 361 | Put custom search path for dynamic libraries into executable. |
| 362 | 362 | ||
| 363 | @item -Wl,-Ipath | ||
| 364 | @item -Wl,--dynamic-linker=path | ||
| 365 | Set the ELF interpreter (dynamic linker). This defaults to the value of the | ||
| 366 | environment variable @env{LD_SO} if set, or a compiled-in default. | ||
| 367 | |||
| 363 | @item -Wl,--enable-new-dtags | 368 | @item -Wl,--enable-new-dtags |
| 364 | When putting a custom search path for dynamic libraries into the executable, | 369 | When putting a custom search path for dynamic libraries into the executable, |
| 365 | create the new ELF dynamic tag DT_RUNPATH instead of the old legacy DT_RPATH. | 370 | create the new ELF dynamic tag DT_RUNPATH instead of the old legacy DT_RPATH. |
| @@ -152,6 +152,8 @@ static const char help2[] = · 151 unmodified lines | |||
| 152 | " -soname= set DT_SONAME elf tag\n" | 152 | " -soname= set DT_SONAME elf tag\n" |
| 153 | #if defined(TCC_TARGET_MACHO) | 153 | #if defined(TCC_TARGET_MACHO) |
| 154 | " -install_name= set DT_SONAME elf tag (soname macOS alias)\n" | 154 | " -install_name= set DT_SONAME elf tag (soname macOS alias)\n" |
| 155 | #else | ||
| 156 | " -Ipath, -dynamic-linker=path set ELF interpreter to path" | ||
| 155 | #endif | 157 | #endif |
| 156 | " -Bsymbolic set DT_SYMBOLIC elf tag\n" | 158 | " -Bsymbolic set DT_SYMBOLIC elf tag\n" |
| 157 | " -oformat=[elf32/64-* binary] set executable output format\n" | 159 | " -oformat=[elf32/64-* binary] set executable output format\n" |
| @@ -802,6 +802,7 @@ struct TCCState { · 801 unmodified lines | |||
| 802 | char *tcc_lib_path; /* CONFIG_TCCDIR or -B option */ | 802 | char *tcc_lib_path; /* CONFIG_TCCDIR or -B option */ |
| 803 | char *soname; /* as specified on the command line (-soname) */ | 803 | char *soname; /* as specified on the command line (-soname) */ |
| 804 | char *rpath; /* as specified on the command line (-Wl,-rpath=) */ | 804 | char *rpath; /* as specified on the command line (-Wl,-rpath=) */ |
| 805 | char *elfint; /* -Wl,-I on command line, LD_SO in environment, or DEFAULT_ELFINTERP(this) */ | ||
| 805 | char *elf_entryname; /* "_start" unless set */ | 806 | char *elf_entryname; /* "_start" unless set */ |
| 806 | char *init_symbol; /* symbols to call at load-time (not used currently) */ | 807 | char *init_symbol; /* symbols to call at load-time (not used currently) */ |
| 807 | char *fini_symbol; /* symbols to call at unload-time (not used currently) */ | 808 | char *fini_symbol; /* symbols to call at unload-time (not used currently) */ |
| @@ -2850,7 +2850,9 @@ static int elf_output_file(TCCState *s1, const char *filename) · 2849 unmodified lines | |||
| 2850 | if (file_type & TCC_OUTPUT_EXE) { | 2850 | if (file_type & TCC_OUTPUT_EXE) { |
| 2851 | char *ptr; | 2851 | char *ptr; |
| 2852 | /* allow override the dynamic loader */ | 2852 | /* allow override the dynamic loader */ |
| 2853 | const char *elfint = getenv("LD_SO"); | 2853 | const char *elfint = s1->elfint; |
| 2854 | if (elfint == NULL) | ||
| 2855 | elfint = getenv("LD_SO"); | ||
| 2854 | if (elfint == NULL) | 2856 | if (elfint == NULL) |
| 2855 | elfint = DEFAULT_ELFINTERP(s1); | 2857 | elfint = DEFAULT_ELFINTERP(s1); |
| 2856 | /* add interpreter section only if executable */ | 2858 | /* add interpreter section only if executable */ |