[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Tinycc-devel] [PATCH 1/3] Add -Wl, -I and -Wl, -dynamic-linker options
From: |
remph |
Subject: |
[Tinycc-devel] [PATCH 1/3] Add -Wl, -I and -Wl, -dynamic-linker options |
Date: |
Sun, 16 Feb 2025 16:56:43 +0000 |
Compatible with ld.bfd, gold, lld and mold. Also, document existing
behaviour of LD_SO environment variable
---
libtcc.c | 7 +++++++
tcc-doc.texi | 5 +++++
tcc.c | 2 ++
tcc.h | 1 +
tccelf.c | 4 +++-
5 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/libtcc.c b/libtcc.c
index 44cca386..1c4b4a55 100644
--- a/libtcc.c
+++ b/libtcc.c
@@ -1428,6 +1428,13 @@ static int tcc_set_linker(TCCState *s, const char
*option)
s->rdynamic = 1;
} else if (link_option(option, "rpath=", &p)) {
copy_linker_arg(&s->rpath, p, ':');
+ } else if (link_option(option, "dynamic-linker=", &p)
+ || link_option(option, "I=", &p)) {
+ copy_linker_arg(&s->elfint, p, 0);
+ } else if (strncmp("-I/", option, 3) == 0
+ || strncmp("-I.", option, 3) == 0) {
+ p = option;
+ copy_linker_arg(&s->elfint, option + 2, 0);
} else if (link_option(option, "enable-new-dtags", &p)) {
s->enable_new_dtags = 1;
} else if (link_option(option, "section-alignment=", &p)) {
diff --git a/tcc-doc.texi b/tcc-doc.texi
index 62aabf99..47acb528 100644
--- a/tcc-doc.texi
+++ b/tcc-doc.texi
@@ -360,6 +360,11 @@ Generate an object file combining all input files.
@item -Wl,-rpath=path
Put custom search path for dynamic libraries into executable.
+@item -Wl,-Ipath
+@item -Wl,--dynamic-linker=path
+Set the ELF interpreter (dynamic linker). This defaults to the value of the
+environment variable @env{LD_SO} if set, or a compiled-in default.
+
@item -Wl,--enable-new-dtags
When putting a custom search path for dynamic libraries into the executable,
create the new ELF dynamic tag DT_RUNPATH instead of the old legacy DT_RPATH.
diff --git a/tcc.c b/tcc.c
index 0363d5aa..abe1a70a 100644
--- a/tcc.c
+++ b/tcc.c
@@ -152,6 +152,8 @@ static const char help2[] =
" -soname= set DT_SONAME elf tag\n"
#if defined(TCC_TARGET_MACHO)
" -install_name= set DT_SONAME elf tag (soname macOS
alias)\n"
+#else
+ " -Ipath, -dynamic-linker=path set ELF interpreter to path"
#endif
" -Bsymbolic set DT_SYMBOLIC elf tag\n"
" -oformat=[elf32/64-* binary] set executable output format\n"
diff --git a/tcc.h b/tcc.h
index 84e27bc2..44da52f1 100644
--- a/tcc.h
+++ b/tcc.h
@@ -802,6 +802,7 @@ struct TCCState {
char *tcc_lib_path; /* CONFIG_TCCDIR or -B option */
char *soname; /* as specified on the command line (-soname) */
char *rpath; /* as specified on the command line (-Wl,-rpath=) */
+ char *elfint; /* -Wl,-I on command line, LD_SO in environment, or
DEFAULT_ELFINTERP(this) */
char *elf_entryname; /* "_start" unless set */
char *init_symbol; /* symbols to call at load-time (not used currently) */
char *fini_symbol; /* symbols to call at unload-time (not used currently)
*/
diff --git a/tccelf.c b/tccelf.c
index 2ac52b1d..7df46f98 100644
--- a/tccelf.c
+++ b/tccelf.c
@@ -2850,7 +2850,9 @@ static int elf_output_file(TCCState *s1, const char
*filename)
if (file_type & TCC_OUTPUT_EXE) {
char *ptr;
/* allow override the dynamic loader */
- const char *elfint = getenv("LD_SO");
+ const char *elfint = s1->elfint;
+ if (elfint == NULL)
+ elfint = getenv("LD_SO");
if (elfint == NULL)
elfint = DEFAULT_ELFINTERP(s1);
/* add interpreter section only if executable */
--
2.48.1