History

Add -Wl,-I and -Wl,-dynamic-linker options

Compatible with ld.bfd, gold, lld and mold. Also, document existing behaviour of LD_SO environment variable

remph committed 1 year ago

Commit ec60d281 parent f8bd1365 files · +18 −1Browse files

Unified · Split

5 files
  1. libtcc.c +7 −0
  2. tcc-doc.texi +5 −0
  3. tcc.c +2 −0
  4. tcc.h +1 −0
  5. tccelf.c +3 −1
libtcc.c+7−0
@@ -1428,6 +1428,13 @@ static int tcc_set_linker(TCCState *s, const char *option) · 1427 unmodified lines
14281428 s->rdynamic = 1;
14291429 } else if (link_option(option, "rpath=", &p)) {
14301430 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);
14311438 } else if (link_option(option, "enable-new-dtags", &p)) {
14321439 s->enable_new_dtags = 1;
14331440 } else if (link_option(option, "section-alignment=", &p)) {
tcc-doc.texi+5−0
@@ -360,6 +360,11 @@ Generate an object file combining all input files. · 359 unmodified lines
360360 @item -Wl,-rpath=path
361361 Put custom search path for dynamic libraries into executable.
362362
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+
363368 @item -Wl,--enable-new-dtags
364369 When putting a custom search path for dynamic libraries into the executable,
365370 create the new ELF dynamic tag DT_RUNPATH instead of the old legacy DT_RPATH.
tcc.c+2−0
@@ -152,6 +152,8 @@ static const char help2[] = · 151 unmodified lines
152152 " -soname= set DT_SONAME elf tag\n"
153153 #if defined(TCC_TARGET_MACHO)
154154 " -install_name= set DT_SONAME elf tag (soname macOS alias)\n"
155+#else
156+ " -Ipath, -dynamic-linker=path set ELF interpreter to path"
155157 #endif
156158 " -Bsymbolic set DT_SYMBOLIC elf tag\n"
157159 " -oformat=[elf32/64-* binary] set executable output format\n"
tcc.h+1−0
@@ -802,6 +802,7 @@ struct TCCState { · 801 unmodified lines
802802 char *tcc_lib_path; /* CONFIG_TCCDIR or -B option */
803803 char *soname; /* as specified on the command line (-soname) */
804804 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) */
805806 char *elf_entryname; /* "_start" unless set */
806807 char *init_symbol; /* symbols to call at load-time (not used currently) */
807808 char *fini_symbol; /* symbols to call at unload-time (not used currently) */
tccelf.c+3−1
@@ -2850,7 +2850,9 @@ static int elf_output_file(TCCState *s1, const char *filename) · 2849 unmodified lines
28502850 if (file_type & TCC_OUTPUT_EXE) {
28512851 char *ptr;
28522852 /* 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");
28542856 if (elfint == NULL)
28552857 elfint = DEFAULT_ELFINTERP(s1);
28562858 /* add interpreter section only if executable */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t