configure & tcc.h: include & lib searchpath cleanup

configure:
- remove CONFIG_USE_LIBGCC, --with-libgcc
- remove CONFIG_LDDIR
- remove CONFIG_USR_INCLUDE
- add -q switch for quiet (=no) output

tcc.h:
- remove /usr/local/include&lib search paths

arm-gen.c:
- remove default_elfinterp() function

tccelf.c:
- setup the ELF-interp in tccelf_new()
This commit is contained in:
grischka 2026-02-02 15:54:11 +01:00
parent 923fba83f1
commit 6daf1617ef
8 changed files with 97 additions and 122 deletions

View File

@ -158,10 +158,27 @@ all : cross
endif endif
# -------------------------------------------- # --------------------------------------------
T = $(or $(CROSS_TARGET),$(NATIVE_TARGET))
T = $(or $(CROSS_TARGET),$(NATIVE_TARGET),unknown)
X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-) X = $(if $(CROSS_TARGET),$(CROSS_TARGET)-)
ifneq ($(T),$(NATIVE_TARGET))
$(if $(DEF-$T),,$(error error: unknown target: '$T'))
ifneq ($(CONFIG_WIN32),yes)
DEF-win = -DCONFIG_TCCDIR="\"$(tccdir)/win32\""
endif
# some default config for cross compilers
TRIPLET-i386 = i686-linux-gnu
TRIPLET-x86_64 = x86_64-linux-gnu
TRIPLET-arm = arm-linux-gnueabihf
TRIPLET-arm64 = aarch64-linux-gnu
TRIPLET-riscv64 = riscv64-linux-gnu
ifneq ($(TRIPLET-$T),)
# assume support files in "/usr/<triplet>"
ROOT-$T = /usr/$(TRIPLET-$T)
INC-$T = {B}/include:{R}/include
LIB-$T = {R}/lib:{B}
CRT-$T = {R}/lib
endif
DEFINES += $(DEF-$T) DEFINES += $(DEF-$T)
DEFINES += $(if $(ROOT-$T),-DCONFIG_SYSROOT="\"$(ROOT-$T)\"") DEFINES += $(if $(ROOT-$T),-DCONFIG_SYSROOT="\"$(ROOT-$T)\"")
DEFINES += $(if $(CRT-$T),-DCONFIG_TCC_CRTPREFIX="\"$(CRT-$T)\"") DEFINES += $(if $(CRT-$T),-DCONFIG_TCC_CRTPREFIX="\"$(CRT-$T)\"")
@ -169,36 +186,17 @@ DEFINES += $(if $(LIB-$T),-DCONFIG_TCC_LIBPATHS="\"$(LIB-$T)\"")
DEFINES += $(if $(INC-$T),-DCONFIG_TCC_SYSINCLUDEPATHS="\"$(INC-$T)\"") DEFINES += $(if $(INC-$T),-DCONFIG_TCC_SYSINCLUDEPATHS="\"$(INC-$T)\"")
DEFINES += $(if $(ELF-$T),-DCONFIG_TCC_ELFINTERP="\"$(ELF-$T)\"") DEFINES += $(if $(ELF-$T),-DCONFIG_TCC_ELFINTERP="\"$(ELF-$T)\"")
DEFINES += $(DEF-$(or $(findstring win,$T),unx)) DEFINES += $(DEF-$(or $(findstring win,$T),unx))
DEFINES += -DCONFIG_TCC_CROSSPREFIX="\"$X\""
ifneq ($(X),)
$(if $(DEF-$T),,$(error error: unknown target: '$T'))
DEF-$(NATIVE_TARGET) =
DEF-$T += -DCONFIG_TCC_CROSSPREFIX="\"$X\""
ifneq ($(CONFIG_WIN32),yes)
DEF-win += -DCONFIG_TCCDIR="\"$(tccdir)/win32\""
endif
else
# using values from config.h
DEF-$(NATIVE_TARGET) =
endif endif
# include custom configuration (see make help) # include custom configuration (see make help)
-include config-extra.mak -include config-extra.mak
ifneq ($(T),$(NATIVE_TARGET)) # so one can use: make EXTRA-DEFS=...
# assume support files for cross-targets in "/usr/<triplet>" by default DEFINES += $(EXTRA-DEFS)
TRIPLET-i386 ?= i686-linux-gnu
TRIPLET-x86_64 ?= x86_64-linux-gnu # find config.h with 'out of tree' builds
TRIPLET-arm ?= arm-linux-gnueabi DEFINES += -I$(TOP)
TRIPLET-arm64 ?= aarch64-linux-gnu
TRIPLET-riscv64 ?= riscv64-linux-gnu
MARCH-i386 ?= i386-linux-gnu
MARCH-$T ?= $(TRIPLET-$T)
TR = $(if $(TRIPLET-$T),$T,ignored)
CRT-$(TR) ?= /usr/$(TRIPLET-$T)/lib
LIB-$(TR) ?= {B}:/usr/$(TRIPLET-$T)/lib:/usr/lib/$(MARCH-$T)
INC-$(TR) ?= {B}/include:/usr/$(TRIPLET-$T)/include:/usr/include
endif
CORE_FILES = tcc.c tcctools.c libtcc.c tccpp.c tccgen.c tccdbg.c tccelf.c tccasm.c tccrun.c CORE_FILES = tcc.c tcctools.c libtcc.c tccpp.c tccgen.c tccdbg.c tccelf.c tccasm.c tccrun.c
CORE_FILES += tcc.h config.h libtcc.h tcctok.h CORE_FILES += tcc.h config.h libtcc.h tcctok.h
@ -209,7 +207,6 @@ x86_64-win32_FILES = $(x86_64_FILES) tccpe.c
x86_64-osx_FILES = $(x86_64_FILES) tccmacho.c x86_64-osx_FILES = $(x86_64_FILES) tccmacho.c
arm_FILES = $(CORE_FILES) arm-gen.c arm-link.c arm-asm.c arm-tok.h arm_FILES = $(CORE_FILES) arm-gen.c arm-link.c arm-asm.c arm-tok.h
arm-wince_FILES = $(arm_FILES) tccpe.c arm-wince_FILES = $(arm_FILES) tccpe.c
arm-eabihf_FILES = $(arm_FILES)
arm-fpa_FILES = $(arm_FILES) arm-fpa_FILES = $(arm_FILES)
arm-fpa-ld_FILES = $(arm_FILES) arm-fpa-ld_FILES = $(arm_FILES)
arm-vfp_FILES = $(arm_FILES) arm-vfp_FILES = $(arm_FILES)
@ -241,7 +238,6 @@ $(CROSS_TARGET)-tcc.o : DEFINES += -DONE_SOURCE=0
endif endif
# native tcc always made from tcc.o and libtcc.[so|a] # native tcc always made from tcc.o and libtcc.[so|a]
tcc.o : DEFINES += -DONE_SOURCE=0 tcc.o : DEFINES += -DONE_SOURCE=0
DEFINES += -I$(TOP)
GITHASH:=$(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo no) GITHASH:=$(shell git rev-parse --abbrev-ref HEAD 2>/dev/null || echo no)
ifneq ($(GITHASH),no) ifneq ($(GITHASH),no)
@ -340,7 +336,7 @@ FORCE:
# some versions of gnu-make do not recognize 'command' as a shell builtin # some versions of gnu-make do not recognize 'command' as a shell builtin
WHICH = sh -c 'command -v $1' WHICH = sh -c 'command -v $1'
run-if = $(if $(shell $(call WHICH,$1)),$S $1 $2) run-if = $(if $(shell $(call WHICH,$1)),$S $1 $2,@echo "(skipping $@ - no $1)")
S = $(if $(findstring yes,$(SILENT)),@$(info * $@)) S = $(if $(findstring yes,$(SILENT)),@$(info * $@))
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
@ -501,14 +497,14 @@ distclean: clean
help: help:
@echo "make" @echo "make"
@echo " build native compiler (from separate objects)" @echo " build native compiler (from separate objects)"
@echo "make cross"
@echo " build cross compilers (from one source)"
@echo "make ONE_SOURCE=no/yes SILENT=no/yes" @echo "make ONE_SOURCE=no/yes SILENT=no/yes"
@echo " force building from separate/one object(s), less/more silently" @echo " force building from separate/one object(s), less/more silently"
@echo "make cross-TARGET" @echo "make cross-TARGET"
@echo " build one specific cross compiler for 'TARGET'. Currently supported:" @echo " build one specific cross compiler for 'TARGET'. Currently supported:"
@echo " $(wordlist 1,8,$(TCC_X))" @echo " $(wordlist 1,8,$(TCC_X))"
@echo " $(wordlist 9,99,$(TCC_X))" @echo " $(wordlist 9,99,$(TCC_X))"
@echo "make cross"
@echo " build all cross compilers"
@echo "make test" @echo "make test"
@echo " run all tests" @echo " run all tests"
@echo "make tests2.all / make tests2.37 / make tests2.37+" @echo "make tests2.all / make tests2.37 / make tests2.37+"

View File

@ -133,11 +133,8 @@ enum {
#define CHAR_IS_UNSIGNED #define CHAR_IS_UNSIGNED
#ifdef TCC_ARM_HARDFLOAT #define ARM_SOFTFP_FLOAT 0
# define ARM_FLOAT_ABI ARM_HARD_FLOAT #define ARM_HARD_FLOAT 1
#else
# define ARM_FLOAT_ABI ARM_SOFTFP_FLOAT
#endif
/******************************************************/ /******************************************************/
#else /* ! TARGET_DEFS_ONLY */ #else /* ! TARGET_DEFS_ONLY */
@ -160,8 +157,6 @@ ST_DATA const char * const target_machine_defs =
#endif #endif
; ;
enum float_abi float_abi;
ST_DATA const int reg_classes[NB_REGS] = { ST_DATA const int reg_classes[NB_REGS] = {
/* r0 */ RC_INT | RC_R0, /* r0 */ RC_INT | RC_R0,
/* r1 */ RC_INT | RC_R1, /* r1 */ RC_INT | RC_R1,
@ -180,6 +175,7 @@ ST_DATA const int reg_classes[NB_REGS] = {
#endif #endif
}; };
static int float_abi;
static int func_sub_sp_offset, last_itod_magic; static int func_sub_sp_offset, last_itod_magic;
static int leaffunc; static int leaffunc;
@ -241,16 +237,6 @@ static int regmask(int r) {
/******************************************************/ /******************************************************/
#if defined(TCC_ARM_EABI) && !defined(CONFIG_TCC_ELFINTERP)
const char *default_elfinterp(struct TCCState *s)
{
if (s->float_abi == ARM_HARD_FLOAT)
return "/lib/ld-linux-armhf.so.3";
else
return "/lib/ld-linux.so.3";
}
#endif
void o(uint32_t i) void o(uint32_t i)
{ {
/* this is a good place to start adding big-endian support*/ /* this is a good place to start adding big-endian support*/

View File

@ -18,11 +18,6 @@
#define PCRELATIVE_DLLPLT 1 #define PCRELATIVE_DLLPLT 1
#define RELOCATE_DLLPLT 1 #define RELOCATE_DLLPLT 1
enum float_abi {
ARM_SOFTFP_FLOAT,
ARM_HARD_FLOAT,
};
#else /* !TARGET_DEFS_ONLY */ #else /* !TARGET_DEFS_ONLY */
#include "tcc.h" #include "tcc.h"

23
configure vendored
View File

@ -35,13 +35,11 @@ mingw32="no"
LIBSUF=".a" LIBSUF=".a"
EXESUF="" EXESUF=""
DLLSUF=".so" DLLSUF=".so"
tcc_usrinclude=""
tcc_sysincludepaths="" tcc_sysincludepaths=""
tcc_libpaths="" tcc_libpaths=""
tcc_crtprefix="" tcc_crtprefix=""
tcc_elfinterp="" tcc_elfinterp=""
triplet= triplet=
tcc_lddir=
confvars= confvars=
suggest="yes" suggest="yes"
gcc_major=0 gcc_major=0
@ -53,6 +51,7 @@ cpuver=
dwarf= dwarf=
targetos= targetos=
build_cross= build_cross=
quiet=
# use CC/AR from environment when set # use CC/AR from environment when set
test -n "$CC" && cc="$CC" test -n "$CC" && cc="$CC"
@ -160,8 +159,6 @@ for opt do
;; ;;
--debug) confvars_set debug --debug) confvars_set debug
;; ;;
--with-libgcc) confvars_set libgcc
;;
--with-selinux) confvars_set selinux --with-selinux) confvars_set selinux
;; ;;
--tcc-switches=*) assign_opt "$opt" tcc_switches --tcc-switches=*) assign_opt "$opt" tcc_switches
@ -174,6 +171,8 @@ for opt do
;; ;;
--help|-h) show_help="yes" --help|-h) show_help="yes"
;; ;;
-q) quiet=yes
;;
*) echo "configure: WARNING: unrecognized option $opt" *) echo "configure: WARNING: unrecognized option $opt"
;; ;;
esac esac
@ -197,6 +196,7 @@ Standard options:
--docdir=DIR documentation in DIR [SHAREDIR/doc/tcc] --docdir=DIR documentation in DIR [SHAREDIR/doc/tcc]
--mandir=DIR man documentation in DIR [SHAREDIR/man] --mandir=DIR man documentation in DIR [SHAREDIR/man]
--infodir=DIR info documentation in DIR [SHAREDIR/info] --infodir=DIR info documentation in DIR [SHAREDIR/info]
-q be quiet
Advanced options (experts only): Advanced options (experts only):
--source-path=PATH path of source code [$source_path] --source-path=PATH path of source code [$source_path]
@ -210,9 +210,8 @@ Advanced options (experts only):
--disable-static make libtcc.so instead of libtcc.a --disable-static make libtcc.so instead of libtcc.a
--enable-static make libtcc.a instead of libtcc.dll (win32) --enable-static make libtcc.a instead of libtcc.dll (win32)
--disable-rpath disable use of -rpath with libtcc.so --disable-rpath disable use of -rpath with libtcc.so
--with-libgcc use libgcc_s.so.1 instead of libtcc1.a
--with-selinux use mmap for executable memory (tcc -run) --with-selinux use mmap for executable memory (tcc -run)
--enable-cross build cross compilers (see also 'make help') --enable-cross build all cross compilers (see also 'make help')
--sysincludepaths=... specify system include paths, colon separated --sysincludepaths=... specify system include paths, colon separated
--libpaths=... specify system library paths, colon separated --libpaths=... specify system library paths, colon separated
@ -367,6 +366,7 @@ case $targetos in
cc=`command -v cc` cc=`command -v cc`
cc=`readlink $cc || echo clang` cc=`readlink $cc || echo clang`
tcc_usrinclude="`xcrun --show-sdk-path`/usr/include" tcc_usrinclude="`xcrun --show-sdk-path`/usr/include"
default tcc_sysincludepaths "{B}/include:$tcc_usrinclude"
if test "${confvars%new_macho*}" = "${confvars}"; then if test "${confvars%new_macho*}" = "${confvars}"; then
# if new_macho was not specified and (known) ver <= 10, use old (=no) # if new_macho was not specified and (known) ver <= 10, use old (=no)
osxver=$(sw_vers -productVersion 2>/dev/null) # X.Y.Z osxver=$(sw_vers -productVersion 2>/dev/null) # X.Y.Z
@ -478,7 +478,8 @@ if test -z "$build_cross"; then
if test -z "$triplet"; then if test -z "$triplet"; then
case $cpu in x86_64|arm64|riscv64) case $cpu in x86_64|arm64|riscv64)
if test -f "/usr/lib64/crti.o" ; then if test -f "/usr/lib64/crti.o" ; then
tcc_lddir="lib64" default tcc_libpaths "{B}:/usr/lib64"
default tcc_crtprefix "/usr/lib64"
fi fi
esac esac
fi fi
@ -552,6 +553,7 @@ fi
fcho() { if test -n "$2"; then echo "$1$2"; fi } fcho() { if test -n "$2"; then echo "$1$2"; fi }
if test -z "$quiet"; then
fcho "Binary directory " "$bindir" fcho "Binary directory " "$bindir"
fcho "TinyCC directory " "$tccdir" fcho "TinyCC directory " "$tccdir"
fcho "Library directory " "$libdir" fcho "Library directory " "$libdir"
@ -560,7 +562,6 @@ fcho "Manual directory " "$mandir"
fcho "Info directory " "$infodir" fcho "Info directory " "$infodir"
fcho "Doc directory " "$docdir" fcho "Doc directory " "$docdir"
fcho "Target root prefix " "$sysroot" fcho "Target root prefix " "$sysroot"
fcho "/usr/include dir " "$tcc_usrinclude"
echo "Source path $source_path" echo "Source path $source_path"
echo "Build OS $(uname -m -s)" echo "Build OS $(uname -m -s)"
echo "C compiler $cc ($gcc_major.$gcc_minor)" echo "C compiler $cc ($gcc_major.$gcc_minor)"
@ -574,6 +575,7 @@ fcho "Elfinterp " "$tcc_elfinterp"
fcho "Switches " "$tcc_switches" fcho "Switches " "$tcc_switches"
fcho "Config " "${confvars# }" fcho "Config " "${confvars# }"
echo "Creating config.mak and config.h" echo "Creating config.mak and config.h"
fi
version=$(head "$source_path/VERSION") version=$(head "$source_path/VERSION")
@ -691,7 +693,6 @@ for v in $cpu $confvars ; do
esac esac
;; ;;
# other # other
CONFIG_libgcc=yes) print_num CONFIG_USE_LIBGCC 1 ;;
CONFIG_selinux=yes) print_num CONFIG_SELINUX 1 ;; CONFIG_selinux=yes) print_num CONFIG_SELINUX 1 ;;
CONFIG_pie=yes) print_num CONFIG_TCC_PIE 1 ;; CONFIG_pie=yes) print_num CONFIG_TCC_PIE 1 ;;
CONFIG_pic=yes) print_num CONFIG_TCC_PIC 1 ;; CONFIG_pic=yes) print_num CONFIG_TCC_PIC 1 ;;
@ -706,13 +707,11 @@ for v in $cpu $confvars ; do
esac esac
done done
print_str CONFIG_USR_INCLUDE "$tcc_usrinclude"
print_str CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths" print_str CONFIG_TCC_SYSINCLUDEPATHS "$tcc_sysincludepaths"
print_str CONFIG_TCC_LIBPATHS "$tcc_libpaths" print_str CONFIG_TCC_LIBPATHS "$tcc_libpaths"
print_str CONFIG_TCC_CRTPREFIX "$tcc_crtprefix" print_str CONFIG_TCC_CRTPREFIX "$tcc_crtprefix"
print_str CONFIG_TCC_ELFINTERP "$tcc_elfinterp" print_str CONFIG_TCC_ELFINTERP "$tcc_elfinterp"
print_str CONFIG_TCC_SWITCHES "$tcc_switches" print_str CONFIG_TCC_SWITCHES "$tcc_switches"
print_str CONFIG_LDDIR "$tcc_lddir"
print_str CONFIG_TRIPLET "$triplet" print_str CONFIG_TRIPLET "$triplet"
print_str CONFIG_OS_RELEASE "$os_release" print_str CONFIG_OS_RELEASE "$os_release"
echo "#endif" >> $TMPH && echo >> $TMPH echo "#endif" >> $TMPH && echo >> $TMPH
@ -724,7 +723,7 @@ print_num CONFIG_TCC_PREDEFS "$predefs"
diff $TMPH config.h >/dev/null 2>&1 diff $TMPH config.h >/dev/null 2>&1
if test $? -ne 0 ; then if test $? -ne 0 ; then
mv -f $TMPH config.h mv -f $TMPH config.h
else elif test -z "$quiet"; then
echo "config.h is unchanged" echo "config.h is unchanged"
fi fi

View File

@ -896,8 +896,8 @@ LIBTCCAPI TCCState *tcc_new(void)
#if defined TCC_TARGET_MACHO /* || defined TCC_TARGET_PE */ #if defined TCC_TARGET_MACHO /* || defined TCC_TARGET_PE */
s->leading_underscore = 1; s->leading_underscore = 1;
#endif #endif
#ifdef TCC_TARGET_ARM #ifdef TCC_ARM_HARDFLOAT
s->float_abi = ARM_FLOAT_ABI; s->float_abi = ARM_HARD_FLOAT;
#endif #endif
#ifdef CONFIG_NEW_DTAGS #ifdef CONFIG_NEW_DTAGS
s->enable_new_dtags = 1; s->enable_new_dtags = 1;
@ -995,10 +995,12 @@ LIBTCCAPI int tcc_set_output_type(TCCState *s, int output_type)
/* allow linking with system dll's directly */ /* allow linking with system dll's directly */
tcc_add_systemdir(s); tcc_add_systemdir(s);
# endif # endif
#elif defined TCC_TARGET_MACHO #elif defined TCC_TARGET_MACHO
# ifdef TCC_IS_NATIVE # ifdef TCC_IS_NATIVE
tcc_add_macos_sdkpath(s); tcc_add_macos_sdkpath(s);
# endif # endif
#else #else
/* paths for crt objects */ /* paths for crt objects */
tcc_split_path(s, &s->crt_paths, &s->nb_crt_paths, CONFIG_TCC_CRTPREFIX); tcc_split_path(s, &s->crt_paths, &s->nb_crt_paths, CONFIG_TCC_CRTPREFIX);
@ -1362,10 +1364,11 @@ struct lopt {
/* match linker option */ /* match linker option */
static int link_option(struct lopt *o, const char *q) static int link_option(struct lopt *o, const char *q)
{ {
const char *p = o->opt; const char *p;
int c; int c;
redo:
/* there should be 1 or 2 dashes */ /* there should be 1 or 2 dashes */
p = o->opt;
if (*p++ != '-') if (*p++ != '-')
return 0; return 0;
if (*p == '-') if (*p == '-')
@ -1378,16 +1381,22 @@ static int link_option(struct lopt *o, const char *q)
goto succ; /* -Wl,-opt=arg */ goto succ; /* -Wl,-opt=arg */
++q; ++q;
} }
if (c == '=' || c == ':') {
if (*p == '\0') { if (*p == '\0') {
if (c == '|')
goto succ;
if (c == '=' || c == ':') {
if (o->s->link_optind + 1 < o->s->link_argc) { if (o->s->link_optind + 1 < o->s->link_argc) {
p = o->s->link_argv[++o->s->link_optind]; p = o->s->link_argv[++o->s->link_optind];
goto succ; /* -Wl,-opt,arg */ goto succ; /* -Wl,-opt,arg */
} }
o->match = 1; /* -Wl,-opt -Wl,arg */ o->match = 1; /* -Wl,-opt -Wl,arg */
return 0;
}
} else if (c == ':') } else if (c == ':')
goto succ; /* -Wl,-Iarg */ goto succ; /* -Wl,-Iarg */
} while (*q)
if (*q++ == '|')
goto redo;
return 0; return 0;
succ: succ:
o->arg = p; o->arg = p;
@ -1415,9 +1424,9 @@ static int tcc_set_linker(TCCState *s, const char *optarg)
s->symbolic = 1; s->symbolic = 1;
} else if (link_option(&o, "nostdlib")) { } else if (link_option(&o, "nostdlib")) {
s->nostdlib_paths = 1; s->nostdlib_paths = 1;
} else if (link_option(&o, "e=") || link_option(&o, "entry=")) { } else if (link_option(&o, "e=|entry=")) {
tcc_set_str(&s->elf_entryname, o.arg); tcc_set_str(&s->elf_entryname, o.arg);
} else if (link_option(&o, "image-base=") || link_option(&o, "Ttext=")) { } else if (link_option(&o, "image-base=|Ttext=")) {
s->text_addr = strtoull(o.arg, &end, 16); s->text_addr = strtoull(o.arg, &end, 16);
s->has_text_addr = 1; s->has_text_addr = 1;
} else if (link_option(&o, "init=")) { } else if (link_option(&o, "init=")) {
@ -1446,18 +1455,17 @@ static int tcc_set_linker(TCCState *s, const char *optarg)
#endif #endif
else else
goto err; goto err;
} else if (link_option(&o, "export-all-symbols") } else if (link_option(&o, "export-all-symbols|export-dynamic|E")) {
|| link_option(&o, "export-dynamic")) {
s->rdynamic = 1; s->rdynamic = 1;
} else if (link_option(&o, "rpath=")) { } else if (link_option(&o, "rpath=")) {
tcc_concat_str(&s->rpath, o.arg, ':'); tcc_concat_str(&s->rpath, o.arg, ':');
} else if (link_option(&o, "dynamic-linker=") || link_option(&o, "I:")) { } else if (link_option(&o, "dynamic-linker=|I:")) {
tcc_set_str(&s->elfint, o.arg); tcc_set_str(&s->elfint, o.arg);
} else if (link_option(&o, "enable-new-dtags")) { } else if (link_option(&o, "enable-new-dtags")) {
s->enable_new_dtags = 1; s->enable_new_dtags = 1;
} else if (link_option(&o, "section-alignment=")) { } else if (link_option(&o, "section-alignment=")) {
s->section_align = strtoul(o.arg, &end, 16); s->section_align = strtoul(o.arg, &end, 16);
} else if (link_option(&o, "soname=") || link_option(&o, "install_name=")) { } else if (link_option(&o, "soname=|install_name=")) {
tcc_set_str(&s->soname, o.arg); tcc_set_str(&s->soname, o.arg);
} else if (link_option(&o, "whole-archive")) { } else if (link_option(&o, "whole-archive")) {
s->filetype |= AFF_WHOLE_ARCHIVE; s->filetype |= AFF_WHOLE_ARCHIVE;
@ -2024,7 +2032,7 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int *pargc, char ***pargv)
s->float_abi = ARM_HARD_FLOAT; s->float_abi = ARM_HARD_FLOAT;
else else
return tcc_error_noabort("unsupported float abi '%s'", optarg); return tcc_error_noabort("unsupported float abi '%s'", optarg);
break; continue;
#endif #endif
case TCC_OPTION_m: case TCC_OPTION_m:
if (set_flag(s, options_m, optarg) < 0) { if (set_flag(s, options_m, optarg) < 0) {

2
tcc.c
View File

@ -226,7 +226,7 @@ static void print_search_dirs(TCCState *s)
printf("libtcc1:\n %s/%s\n", s->library_paths[0], CONFIG_TCC_CROSSPREFIX TCC_LIBTCC1); printf("libtcc1:\n %s/%s\n", s->library_paths[0], CONFIG_TCC_CROSSPREFIX TCC_LIBTCC1);
#ifdef TCC_TARGET_UNIX #ifdef TCC_TARGET_UNIX
print_dirs("crt", s->crt_paths, s->nb_crt_paths); print_dirs("crt", s->crt_paths, s->nb_crt_paths);
printf("elfinterp:\n %s\n", DEFAULT_ELFINTERP(s)); printf("elfinterp:\n %s\n", s->elfint);
#endif #endif
} }

44
tcc.h
View File

@ -252,15 +252,14 @@ extern long double strtold (const char *__nptr, char **__endptr);
#ifndef CONFIG_SYSROOT #ifndef CONFIG_SYSROOT
# define CONFIG_SYSROOT "" # define CONFIG_SYSROOT ""
#endif #endif
#if !defined CONFIG_TCCDIR && !defined _WIN32 #if !defined CONFIG_TCCDIR && !defined _WIN32
# define CONFIG_TCCDIR "/usr/local/lib/tcc" # define CONFIG_TCCDIR "/usr/local/lib/tcc"
#endif #endif
#ifndef CONFIG_LDDIR
# define CONFIG_LDDIR "lib"
#endif
#ifdef CONFIG_TRIPLET #ifdef CONFIG_TRIPLET
# define USE_TRIPLET(s) s "/" CONFIG_TRIPLET # define USE_TRIPLET(s) s "/" CONFIG_TRIPLET
# define ALSO_TRIPLET(s) USE_TRIPLET(s) ":" s # define ALSO_TRIPLET(s) USE_TRIPLET(s) PATHSEP s
#else #else
# define USE_TRIPLET(s) s # define USE_TRIPLET(s) s
# define ALSO_TRIPLET(s) s # define ALSO_TRIPLET(s) s
@ -268,11 +267,8 @@ extern long double strtold (const char *__nptr, char **__endptr);
/* path to find crt1.o, crti.o and crtn.o */ /* path to find crt1.o, crti.o and crtn.o */
#ifndef CONFIG_TCC_CRTPREFIX #ifndef CONFIG_TCC_CRTPREFIX
# define CONFIG_TCC_CRTPREFIX USE_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) # define CONFIG_TCC_CRTPREFIX \
#endif USE_TRIPLET(CONFIG_SYSROOT "/usr/lib")
#ifndef CONFIG_USR_INCLUDE
# define CONFIG_USR_INCLUDE "/usr/include"
#endif #endif
/* Below: {B} is substituted by CONFIG_TCCDIR (rsp. -B option) */ /* Below: {B} is substituted by CONFIG_TCCDIR (rsp. -B option) */
@ -280,25 +276,22 @@ extern long double strtold (const char *__nptr, char **__endptr);
/* system include paths */ /* system include paths */
#ifndef CONFIG_TCC_SYSINCLUDEPATHS #ifndef CONFIG_TCC_SYSINCLUDEPATHS
# if defined TCC_TARGET_PE || defined _WIN32 # if defined TCC_TARGET_PE || defined _WIN32
# define CONFIG_TCC_SYSINCLUDEPATHS "{B}/include"PATHSEP"{B}/include/winapi" # define CONFIG_TCC_SYSINCLUDEPATHS \
"{B}/include" PATHSEP "{B}/include/winapi"
# else # else
# define CONFIG_TCC_SYSINCLUDEPATHS \ # define CONFIG_TCC_SYSINCLUDEPATHS \
"{B}/include" \ "{B}/include" PATHSEP ALSO_TRIPLET(CONFIG_SYSROOT "/usr/include")
":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/include") \
":" ALSO_TRIPLET(CONFIG_SYSROOT CONFIG_USR_INCLUDE)
# endif # endif
#endif #endif
/* library search paths */ /* library search paths */
#ifndef CONFIG_TCC_LIBPATHS #ifndef CONFIG_TCC_LIBPATHS
# if defined TCC_TARGET_PE || defined _WIN32 # if defined TCC_TARGET_PE || defined _WIN32
# define CONFIG_TCC_LIBPATHS "{B}/lib" # define CONFIG_TCC_LIBPATHS \
"{B}/lib"
# else # else
# define CONFIG_TCC_LIBPATHS \ # define CONFIG_TCC_LIBPATHS \
"{B}" \ "{B}" PATHSEP ALSO_TRIPLET(CONFIG_SYSROOT "/usr/lib")
":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) \
":" ALSO_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) \
":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR)
# endif # endif
#endif #endif
@ -314,28 +307,19 @@ extern long double strtold (const char *__nptr, char **__endptr);
# define CONFIG_TCC_ELFINTERP "/lib64/ld-linux-x86-64.so.2" # define CONFIG_TCC_ELFINTERP "/lib64/ld-linux-x86-64.so.2"
# elif defined(TCC_TARGET_RISCV64) # elif defined(TCC_TARGET_RISCV64)
# define CONFIG_TCC_ELFINTERP "/lib/ld-linux-riscv64-lp64d.so.1" # define CONFIG_TCC_ELFINTERP "/lib/ld-linux-riscv64-lp64d.so.1"
# elif defined(TCC_ARM_EABI) # elif defined(TCC_TARGET_ARM)
# define DEFAULT_ELFINTERP(s) default_elfinterp(s) # define CONFIG_TCC_ELFINTERP "/lib/ld-linux.so.3"
# define CONFIG_TCC_ELFINTERP_ARMHF "/lib/ld-linux-armhf.so.3"
# else # else
# define CONFIG_TCC_ELFINTERP "/lib/ld-linux.so.2" # define CONFIG_TCC_ELFINTERP "/lib/ld-linux.so.2"
# endif # endif
#endif #endif
/* var elf_interp dans *-gen.c */
#ifndef DEFAULT_ELFINTERP
# define DEFAULT_ELFINTERP(s) CONFIG_TCC_ELFINTERP
#endif
/* (target specific) libtcc1.a */ /* (target specific) libtcc1.a */
#ifndef TCC_LIBTCC1 #ifndef TCC_LIBTCC1
# define TCC_LIBTCC1 "libtcc1.a" # define TCC_LIBTCC1 "libtcc1.a"
#endif #endif
/* library to use with CONFIG_USE_LIBGCC instead of libtcc1.a */
#if defined CONFIG_USE_LIBGCC && !defined TCC_LIBGCC
#define TCC_LIBGCC USE_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) "/libgcc_s.so.1"
#endif
/* <cross-prefix-to->libtcc1.a */ /* <cross-prefix-to->libtcc1.a */
#ifndef CONFIG_TCC_CROSSPREFIX #ifndef CONFIG_TCC_CROSSPREFIX
# define CONFIG_TCC_CROSSPREFIX "" # define CONFIG_TCC_CROSSPREFIX ""

View File

@ -110,6 +110,21 @@ ST_FUNC void tccelf_new(TCCState *s)
if (s->elf_entryname) if (s->elf_entryname)
set_global_sym(s, s->elf_entryname, NULL, 0); /* SHN_UNDEF */ set_global_sym(s, s->elf_entryname, NULL, 0); /* SHN_UNDEF */
#endif #endif
#ifndef ELF_OBJ_ONLY
if (NULL == s->elfint && s1->output_type != TCC_OUTPUT_OBJ) {
const char *p = CONFIG_TCC_ELFINTERP;
#ifdef TCC_TARGET_ARM
if (s->float_abi == ARM_HARD_FLOAT)
p = CONFIG_TCC_ELFINTERP_ARMHF;
#endif
#if defined TCC_IS_NATIVE && defined TARGETOS_BSD
/* see commit 55cb2170cd5ce77a7d76dcaf462fad2707281605 */
{ const char *e = getenv("LD_SO"); if (e) p = e; }
#endif
s->elfint = tcc_strdup(p);
}
#endif /* ndef ELF_OBJ_ONLY */
} }
ST_FUNC void free_section(Section *s) ST_FUNC void free_section(Section *s)
@ -2939,18 +2954,10 @@ static int elf_output_file(TCCState *s1, const char *filename)
if (!s1->static_link) { if (!s1->static_link) {
if (file_type & TCC_OUTPUT_EXE) { if (file_type & TCC_OUTPUT_EXE) {
char *ptr;
/* allow override the dynamic loader */
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 */ /* add interpreter section only if executable */
interp = new_section(s1, ".interp", SHT_PROGBITS, SHF_ALLOC); interp = new_section(s1, ".interp", SHT_PROGBITS, SHF_ALLOC);
interp->sh_addralign = 1; interp->sh_addralign = 1;
ptr = section_ptr_add(interp, 1 + strlen(elfint)); put_elf_str(interp, s1->elfint);
strcpy(ptr, elfint);
dyninf.interp = interp; dyninf.interp = interp;
} }