/* Use "-g" as alias for "-g1". Use "-g0" to disable debug */

So not using -g is now the alias for -g0 ?!?

This reverts commit 8759b2581d.
This reverts commit 3ce7bc6efc.
This reverts commit 5fb582ab7f.
This reverts commit aea68dbb40.
This reverts commit fa9c31c3db.
This reverts commit b3bebdb20a.
This reverts commit ecf8e5a00e.
This reverts commit fe6b5c08dc.
This reverts commit e2e5377e7b.
This reverts commit 1cd7998905.
This commit is contained in:
grischka 2022-05-07 23:16:13 +02:00
parent 1cd7998905
commit 56481d554f
18 changed files with 76 additions and 124 deletions

2
.gitignore vendored
View file

@ -28,7 +28,7 @@ c2str
tags tags
TAGS TAGS
tcc.1 tcc.1
tcc.pod *.pod
tcc-doc.html tcc-doc.html
tcc-doc.info tcc-doc.info

View file

@ -8,12 +8,6 @@ ifndef TOP
INCLUDED = no INCLUDED = no
endif endif
# Uncomment the next two commands to allow debug this Makefile
# When enabled, GNU make will no longer execute commands directly.
# All build commands will be executed using the shell. This needs more time
#OLD_SHELL := $(SHELL)
#SHELL = $(info Building $* $(if $<, (from $<))$(if $?, ($? newer)))$(OLD_SHELL)
ifeq ($(findstring $(MAKECMDGOALS),clean distclean),) ifeq ($(findstring $(MAKECMDGOALS),clean distclean),)
include $(TOP)/config.mak include $(TOP)/config.mak
endif endif
@ -244,7 +238,7 @@ endif
# convert "include/tccdefs.h" to "tccdefs_.h" # convert "include/tccdefs.h" to "tccdefs_.h"
%_.h : include/%.h conftest.c %_.h : include/%.h conftest.c
$S$(CC) -DC2STR $(filter %.c,$^) -o c2str$(EXESUF) && ./c2str$(EXESUF) $< $@ $S$(CC) -DC2STR $(filter %.c,$^) -o c2str.exe && ./c2str.exe $< $@
# target specific object rule # target specific object rule
$(X)%.o : %.c $(LIBTCC_INC) $(X)%.o : %.c $(LIBTCC_INC)
@ -261,7 +255,7 @@ tcc$(EXESUF): tcc.o $(LIBTCC)
# Cross Tiny C Compilers # Cross Tiny C Compilers
# (the TCCDEFS_H dependency is only necessary for parallel makes, # (the TCCDEFS_H dependency is only necessary for parallel makes,
# ala 'make -j x86_64-tcc i386-tcc tcc', which would create multiple # ala 'make -j x86_64-tcc i386-tcc tcc', which would create multiple
# c2str and tccdefs_.h files in parallel, leading to access errors. # c2str.exe and tccdefs_.h files in parallel, leading to access errors.
# This forces it to be made only once. Make normally tracks multiple paths # This forces it to be made only once. Make normally tracks multiple paths
# to the same goals and only remakes it once, but that doesn't work over # to the same goals and only remakes it once, but that doesn't work over
# sub-makes like in this target) # sub-makes like in this target)
@ -332,6 +326,8 @@ tcc.1 : tcc-doc.pod
%.pod : %.texi %.pod : %.texi
$(call run-if,perl,$(TOPSRC)/texi2pod.pl $< $@) $(call run-if,perl,$(TOPSRC)/texi2pod.pl $< $@)
doc : $(TCCDOCS)
# -------------------------------------------------------------------------- # --------------------------------------------------------------------------
# install # install
@ -410,10 +406,6 @@ tags : ; ctags $(TAGFILES)
# cannot have both tags and TAGS on windows # cannot have both tags and TAGS on windows
ETAGS : ; etags $(TAGFILES) ETAGS : ; etags $(TAGFILES)
# documentation
doc: tcc-doc.html tcc-doc.info tcc.1
# create release tarball from *current* git branch (including tcc-doc.html # create release tarball from *current* git branch (including tcc-doc.html
# and converting two files to CRLF) # and converting two files to CRLF)
TCC-VERSION = tcc-$(VERSION) TCC-VERSION = tcc-$(VERSION)
@ -443,15 +435,16 @@ testspp.%:
@$(MAKE) -C tests/pp $@ @$(MAKE) -C tests/pp $@
clean: clean:
@rm -f tcc$(EXESUF) tcc_p$(EXESUF) *-tcc$(EXESUF) tcc.pod tags ETAGS @rm -f tcc$(EXESUF) tcc_p$(EXESUF) *-tcc$(EXESUF) tags ETAGS *.pod
@rm -f *.o *.a *.so* *.out *.log lib*.def *.exe *.dll a.out *.dylib *_.h @rm -f *.o *.a *.so* *.out *.log lib*.def *.exe *.dll a.out *.dylib *_.h
@$(MAKE) -s -C lib $@ @$(MAKE) -s -C lib $@
@$(MAKE) -s -C tests $@ @$(MAKE) -s -C tests $@
distclean: clean distclean: clean
@rm -fv config.h config.mak config.texi tcc.1 tcc-doc.info tcc-doc.html @rm -fv config.h config.mak config.texi
@rm -fv $(TCCDOCS)
.PHONY: all clean test tar tags ETAGS distclean install uninstall FORCE .PHONY: all clean test tar tags ETAGS doc distclean install uninstall FORCE
help: help:
@echo "make" @echo "make"

View file

@ -77,21 +77,6 @@ static int asm_parse_vfp_regvar(int t, int double_precision)
return -1; return -1;
} }
__attribute__((unused))
static int asm_parse_vfp_status_regvar(int t)
{
switch (t) {
case TOK_ASM_fpsid:
return 0;
case TOK_ASM_fpscr:
return 1;
case TOK_ASM_fpexc:
return 8;
default:
return -1;
}
}
/* Parse a text containing operand and store the result in OP */ /* Parse a text containing operand and store the result in OP */
static void parse_operand(TCCState *s1, Operand *op) static void parse_operand(TCCState *s1, Operand *op)
{ {
@ -2240,6 +2225,20 @@ static void asm_floating_point_data_processing_opcode(TCCState *s1, int token) {
asm_emit_coprocessor_opcode(condition_code_of_token(token), coprocessor, opcode1, ops[0].reg, (ops[1].type == OP_IM8) ? ops[1].e.v : ops[1].reg, (ops[2].type == OP_IM8) ? ops[2].e.v : ops[2].reg, opcode2, 0); asm_emit_coprocessor_opcode(condition_code_of_token(token), coprocessor, opcode1, ops[0].reg, (ops[1].type == OP_IM8) ? ops[1].e.v : ops[1].reg, (ops[2].type == OP_IM8) ? ops[2].e.v : ops[2].reg, opcode2, 0);
} }
static int asm_parse_vfp_status_regvar(int t)
{
switch (t) {
case TOK_ASM_fpsid:
return 0;
case TOK_ASM_fpscr:
return 1;
case TOK_ASM_fpexc:
return 8;
default:
return -1;
}
}
static void asm_floating_point_status_register_opcode(TCCState* s1, int token) static void asm_floating_point_status_register_opcode(TCCState* s1, int token)
{ {
uint8_t coprocessor = CP_SINGLE_PRECISION_FLOAT; uint8_t coprocessor = CP_SINGLE_PRECISION_FLOAT;

View file

@ -28,6 +28,7 @@ enum float_abi {
#include "tcc.h" #include "tcc.h"
#ifdef NEED_RELOC_TYPE
/* Returns 1 for a code relocation, 0 for a data relocation. For unknown /* Returns 1 for a code relocation, 0 for a data relocation. For unknown
relocations, returns -1. */ relocations, returns -1. */
int code_reloc (int reloc_type) int code_reloc (int reloc_type)
@ -107,7 +108,7 @@ int gotplt_entry_type (int reloc_type)
return -1; return -1;
} }
#ifndef TCC_TARGET_PE #ifdef NEED_BUILD_GOT
ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr) ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
{ {
Section *plt = s1->plt; Section *plt = s1->plt;
@ -177,6 +178,7 @@ ST_FUNC void relocate_plt(TCCState *s1)
} }
} }
#endif #endif
#endif
void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val) void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
{ {

View file

@ -22,6 +22,7 @@
#include "tcc.h" #include "tcc.h"
#ifdef NEED_RELOC_TYPE
/* Returns 1 for a code relocation, 0 for a data relocation. For unknown /* Returns 1 for a code relocation, 0 for a data relocation. For unknown
relocations, returns -1. */ relocations, returns -1. */
int code_reloc (int reloc_type) int code_reloc (int reloc_type)
@ -91,7 +92,7 @@ int gotplt_entry_type (int reloc_type)
return -1; return -1;
} }
__attribute__((unused)) #ifdef NEED_BUILD_GOT
ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr) ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
{ {
Section *plt = s1->plt; Section *plt = s1->plt;
@ -111,7 +112,6 @@ ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_
/* relocate the PLT: compute addresses and offsets in the PLT now that final /* relocate the PLT: compute addresses and offsets in the PLT now that final
address for PLT and GOT are known (see fill_program_header) */ address for PLT and GOT are known (see fill_program_header) */
__attribute__((unused))
ST_FUNC void relocate_plt(TCCState *s1) ST_FUNC void relocate_plt(TCCState *s1)
{ {
uint8_t *p, *p_end; uint8_t *p, *p_end;
@ -166,6 +166,8 @@ ST_FUNC void relocate_plt(TCCState *s1)
} }
} }
} }
#endif
#endif
void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val) void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
{ {

6
configure vendored
View file

@ -27,8 +27,7 @@ mandir=""
infodir="" infodir=""
sysroot="" sysroot=""
cross_prefix="" cross_prefix=""
test -z "$CC" && CC="gcc" cc="gcc"
test -z "$cc" && cc="$CC"
ar="ar" ar="ar"
bigendian="no" bigendian="no"
mingw32="no" mingw32="no"
@ -46,7 +45,7 @@ confvars=
suggest="yes" suggest="yes"
gcc_major=0 gcc_major=0
gcc_minor=0 gcc_minor=0
cc_name="$cc" cc_name="gcc"
ar_set= ar_set=
darwin= darwin=
cpu= cpu=
@ -408,6 +407,7 @@ if test "$cc_name" != "tcc"; then
OPT1="-Wdeclaration-after-statement -fno-strict-aliasing" OPT1="-Wdeclaration-after-statement -fno-strict-aliasing"
# we want -Wno- but gcc does not always reject unknown -Wno- options # we want -Wno- but gcc does not always reject unknown -Wno- options
OPT2="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation" OPT2="-Wpointer-sign -Wsign-compare -Wunused-result -Wformat-truncation"
OPT2="$OPT2 -Wstringop-truncation"
if test "$cc_name" = "clang"; then if test "$cc_name" = "clang"; then
OPT1="$OPT1 -fheinous-gnu-extensions" OPT1="$OPT1 -fheinous-gnu-extensions"
OPT2="$OPT2 -Wstring-plus-int" OPT2="$OPT2 -Wstring-plus-int"

View file

@ -833,6 +833,7 @@ again:
goto next; goto next;
alltypes |= ops[i].type; alltypes |= ops[i].type;
} }
(void)alltypes; /* maybe unused */
/* all is matching ! */ /* all is matching ! */
break; break;
next: ; next: ;

View file

@ -23,7 +23,7 @@
#include "tcc.h" #include "tcc.h"
#ifndef ELF_OBJ_ONLY #ifdef NEED_RELOC_TYPE
/* Returns 1 for a code relocation, 0 for a data relocation. For unknown /* Returns 1 for a code relocation, 0 for a data relocation. For unknown
relocations, returns -1. */ relocations, returns -1. */
int code_reloc (int reloc_type) int code_reloc (int reloc_type)
@ -92,6 +92,7 @@ int gotplt_entry_type (int reloc_type)
return -1; return -1;
} }
#ifdef NEED_BUILD_GOT
ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr) ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
{ {
Section *plt = s1->plt; Section *plt = s1->plt;
@ -169,6 +170,7 @@ ST_FUNC void relocate_plt(TCCState *s1)
} }
} }
#endif #endif
#endif
void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val) void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val)
{ {

View file

@ -836,6 +836,7 @@ LIBTCCAPI void tcc_delete(TCCState *s1)
tcc_free(s1->tcc_lib_path); tcc_free(s1->tcc_lib_path);
tcc_free(s1->soname); tcc_free(s1->soname);
tcc_free(s1->rpath); tcc_free(s1->rpath);
tcc_free(s1->elf_entryname);
tcc_free(s1->init_symbol); tcc_free(s1->init_symbol);
tcc_free(s1->fini_symbol); tcc_free(s1->fini_symbol);
tcc_free(s1->outfile); tcc_free(s1->outfile);
@ -1567,23 +1568,6 @@ static const TCCOption tcc_options[] = {
{ NULL, 0, 0 }, { NULL, 0, 0 },
}; };
typedef struct stdvalue {
uint32_t cversion;
const char * name;
} stdvalue;
/* accepted values for the -std= option */
static const stdvalue std_values[] = {
{ 199901, "c99" },
{ 201112, "c11" },
{ 201710, "c17" },
{ 202000, "c2x" },
{ 199901, "gnu99" },
{ 201112, "gnu11" },
{ 201710, "gnu17" },
{ 202000, "gnu2x" }
};
typedef struct FlagDef { typedef struct FlagDef {
uint16_t offset; uint16_t offset;
uint16_t flags; uint16_t flags;
@ -1837,9 +1821,6 @@ reparse:
break; break;
#endif #endif
case TCC_OPTION_g: case TCC_OPTION_g:
/* Use "-g" as alias for "-g1". Use "-g0" to disable debug */
/* Other common used values: "-g0", "-g1", "-g2" and "-g3" */
/* no failure with unsupported options */
s->do_debug = 1; s->do_debug = 1;
s->dwarf = DWARF_VERSION; s->dwarf = DWARF_VERSION;
if (*optarg == 'd') { if (*optarg == 'd') {
@ -1847,8 +1828,6 @@ reparse:
if (!strncmp(optarg,"dwarf-",6)) if (!strncmp(optarg,"dwarf-",6))
s->dwarf = atoi(optarg + 6); s->dwarf = atoi(optarg + 6);
} }
else if (isnum(*optarg))
s->do_debug = atoi(optarg);
break; break;
case TCC_OPTION_c: case TCC_OPTION_c:
x = TCC_OUTPUT_OBJ; x = TCC_OUTPUT_OBJ;
@ -1873,21 +1852,8 @@ reparse:
s->static_link = 1; s->static_link = 1;
break; break;
case TCC_OPTION_std: case TCC_OPTION_std:
x = 0; if (strcmp(optarg, "=c11") == 0)
if (*optarg == '=') { s->cversion = 201112;
do {
if (strcmp(std_values[x].name, &optarg[1]) == 0) {
x = std_values[x].cversion;
}
else
++x;
} while (x < (sizeof(std_values)/sizeof(stdvalue)));
}
if (x > (sizeof(std_values)/sizeof(stdvalue)))
s->cversion = x;
else
goto unsupported_option;
break; break;
case TCC_OPTION_shared: case TCC_OPTION_shared:
x = TCC_OUTPUT_DLL; x = TCC_OUTPUT_DLL;
@ -2018,11 +1984,7 @@ reparse:
s->filetype = x | (s->filetype & ~AFF_TYPE_MASK); s->filetype = x | (s->filetype & ~AFF_TYPE_MASK);
break; break;
case TCC_OPTION_O: case TCC_OPTION_O:
/* Use "-O" as alias for "-O1". */ s->optimize = atoi(optarg);
/* Other common used values: "-O0", "-O1", "-O2", "-O3" and "-Os" */
/* no failure with unsupported options */
x = *optarg;
s->optimize = isnum(x) ? atoi(optarg) : (x) ? x : 1;
break; break;
case TCC_OPTION_print_search_dirs: case TCC_OPTION_print_search_dirs:
x = OPT_PRINT_DIRS; x = OPT_PRINT_DIRS;

View file

@ -349,7 +349,7 @@ Turn on/off linking of all objects in archives.
Debugger options: Debugger options:
@table @option @table @option
@item -g[x] @item -g
Generate run time stab debug information so that you get clear run time Generate run time stab debug information so that you get clear run time
error messages: @code{ test.c:68: in function 'test5()': dereferencing error messages: @code{ test.c:68: in function 'test5()': dereferencing
invalid pointer} instead of the laconic @code{Segmentation invalid pointer} instead of the laconic @code{Segmentation

2
tcc.c
View file

@ -58,7 +58,7 @@ static const char help[] =
" -soname set name for shared library to be used at runtime\n" " -soname set name for shared library to be used at runtime\n"
" -Wl,-opt[=val] set linker option (see tcc -hh)\n" " -Wl,-opt[=val] set linker option (see tcc -hh)\n"
"Debugger options:\n" "Debugger options:\n"
" -g[x] generate stab runtime debug info\n" " -g generate stab runtime debug info\n"
" -gdwarf[-x] generate dwarf runtime debug info\n" " -gdwarf[-x] generate dwarf runtime debug info\n"
#ifdef CONFIG_TCC_BCHECK #ifdef CONFIG_TCC_BCHECK
" -b compile with built-in memory and bounds checker (implies -g)\n" " -b compile with built-in memory and bounds checker (implies -g)\n"

28
tcc.h
View file

@ -258,9 +258,7 @@ 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 \ # define CONFIG_TCC_CRTPREFIX USE_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR)
ALSO_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) \
":" USE_TRIPLET(CONFIG_SYSROOT "/usr") "/lib"
#endif #endif
#ifndef CONFIG_USR_INCLUDE #ifndef CONFIG_USR_INCLUDE
@ -277,8 +275,6 @@ extern long double strtold (const char *__nptr, char **__endptr);
# define CONFIG_TCC_SYSINCLUDEPATHS \ # define CONFIG_TCC_SYSINCLUDEPATHS \
"{B}/include" \ "{B}/include" \
":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/include") \ ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/include") \
":" USE_TRIPLET(CONFIG_SYSROOT "/usr") "/include" \
":" USE_TRIPLET(CONFIG_SYSROOT "/usr/local") "/include" \
":" ALSO_TRIPLET(CONFIG_SYSROOT CONFIG_USR_INCLUDE) ":" ALSO_TRIPLET(CONFIG_SYSROOT CONFIG_USR_INCLUDE)
# endif # endif
#endif #endif
@ -290,8 +286,6 @@ extern long double strtold (const char *__nptr, char **__endptr);
# else # else
# define CONFIG_TCC_LIBPATHS \ # define CONFIG_TCC_LIBPATHS \
ALSO_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) \ ALSO_TRIPLET(CONFIG_SYSROOT "/usr/" CONFIG_LDDIR) \
":" USE_TRIPLET(CONFIG_SYSROOT "/usr") "/lib" \
":" USE_TRIPLET(CONFIG_SYSROOT "/usr/local") "/lib" \
":" ALSO_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) \ ":" ALSO_TRIPLET(CONFIG_SYSROOT "/" CONFIG_LDDIR) \
":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR) ":" ALSO_TRIPLET(CONFIG_SYSROOT "/usr/local/" CONFIG_LDDIR)
# endif # endif
@ -826,7 +820,7 @@ struct TCCState {
char *tcc_lib_path; /* CONFIG_TCCDIR or -B option */ char *tcc_lib_path; /* CONFIG_TCCDIR or -B option */
char *soname; /* as specified on the command line (-soname) */ char *soname; /* as specified on the command line (-soname) */
char *rpath; /* as specified on the command line (-Wl,-rpath=) */ char *rpath; /* as specified on the command line (-Wl,-rpath=) */
char *elf_entryname; /* "_start" unless set */
char *init_symbol; /* symbols to call at load-time (not used currently) */ char *init_symbol; /* symbols to call at load-time (not used currently) */
char *fini_symbol; /* symbols to call at unload-time (not used currently) */ char *fini_symbol; /* symbols to call at unload-time (not used currently) */
@ -975,8 +969,6 @@ struct TCCState {
Section *verneed_section; Section *verneed_section;
#endif #endif
char *elf_entryname;
#ifdef TCC_IS_NATIVE #ifdef TCC_IS_NATIVE
const char *runtime_main; const char *runtime_main;
void **runtime_mem; void **runtime_mem;
@ -1545,9 +1537,6 @@ ST_FUNC int tcc_load_object_file(TCCState *s1, int fd, unsigned long file_offset
ST_FUNC int tcc_load_archive(TCCState *s1, int fd, int alacarte); ST_FUNC int tcc_load_archive(TCCState *s1, int fd, int alacarte);
ST_FUNC void add_array(TCCState *s1, const char *sec, int c); ST_FUNC void add_array(TCCState *s1, const char *sec, int c);
#if !defined(ELF_OBJ_ONLY) || (defined(TCC_TARGET_MACHO) && defined TCC_IS_NATIVE)
ST_FUNC void build_got_entries(TCCState *s1);
#endif
ST_FUNC struct sym_attr *get_sym_attr(TCCState *s1, int index, int alloc); ST_FUNC struct sym_attr *get_sym_attr(TCCState *s1, int index, int alloc);
ST_FUNC addr_t get_sym_addr(TCCState *s, const char *name, int err, int forc); ST_FUNC addr_t get_sym_addr(TCCState *s, const char *name, int err, int forc);
ST_FUNC void list_elf_symbols(TCCState *s, void *ctx, ST_FUNC void list_elf_symbols(TCCState *s, void *ctx,
@ -1570,6 +1559,9 @@ ST_FUNC void tcc_add_runtime(TCCState *s1);
/* ------------ xxx-link.c ------------ */ /* ------------ xxx-link.c ------------ */
#if !defined ELF_OBJ_ONLY || defined TCC_TARGET_MACHO
ST_FUNC int code_reloc (int reloc_type);
ST_FUNC int gotplt_entry_type (int reloc_type);
/* Whether to generate a GOT/PLT entry and when. NO_GOTPLT_ENTRY is first so /* Whether to generate a GOT/PLT entry and when. NO_GOTPLT_ENTRY is first so
that unknown relocation don't create a GOT or PLT entry */ that unknown relocation don't create a GOT or PLT entry */
enum gotplt_entry { enum gotplt_entry {
@ -1578,15 +1570,17 @@ enum gotplt_entry {
AUTO_GOTPLT_ENTRY, /* generate if sym is UNDEF */ AUTO_GOTPLT_ENTRY, /* generate if sym is UNDEF */
ALWAYS_GOTPLT_ENTRY /* always generate (eg. PLTOFF relocs) */ ALWAYS_GOTPLT_ENTRY /* always generate (eg. PLTOFF relocs) */
}; };
#define NEED_RELOC_TYPE
#if !defined(ELF_OBJ_ONLY) || defined(TCC_TARGET_MACHO) #if !defined TCC_TARGET_MACHO || defined TCC_IS_NATIVE
ST_FUNC int code_reloc (int reloc_type);
ST_FUNC int gotplt_entry_type (int reloc_type);
#if !defined(TCC_TARGET_MACHO) || defined TCC_IS_NATIVE
ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr); ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr);
ST_FUNC void relocate_plt(TCCState *s1); ST_FUNC void relocate_plt(TCCState *s1);
ST_FUNC void build_got_entries(TCCState *s1); /* in tccelf.c */
#define NEED_BUILD_GOT
#endif #endif
#endif #endif
ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val); ST_FUNC void relocate(TCCState *s1, ElfW_Rel *rel, int type, unsigned char *ptr, addr_t addr, addr_t val);
/* ------------ xxx-gen.c ------------ */ /* ------------ xxx-gen.c ------------ */

View file

@ -671,7 +671,7 @@ version_add (TCCState *s1)
} }
dt_verneednum = nb_entries; dt_verneednum = nb_entries;
} }
#endif #endif /* ndef ELF_OBJ_ONLY */
/* add an elf symbol : check if it is already defined and patch /* add an elf symbol : check if it is already defined and patch
it. Return symbol index. NOTE that sh_num can be SHN_UNDEF. */ it. Return symbol index. NOTE that sh_num can be SHN_UNDEF. */
@ -1121,7 +1121,7 @@ static int prepare_dynamic_rel(TCCState *s1, Section *sr)
} }
#endif #endif
#if !defined(ELF_OBJ_ONLY) || (defined(TCC_TARGET_MACHO) && defined TCC_IS_NATIVE) #ifdef NEED_BUILD_GOT
static void build_got(TCCState *s1) static void build_got(TCCState *s1)
{ {
/* if no got, then create it */ /* if no got, then create it */
@ -1354,7 +1354,7 @@ redo:
s1->plt->reloc->sh_info = s1->got->sh_num; s1->plt->reloc->sh_info = s1->got->sh_num;
} }
#endif #endif /* def NEED_BUILD_GOT */
ST_FUNC int set_global_sym(TCCState *s1, const char *name, Section *sec, addr_t offs) ST_FUNC int set_global_sym(TCCState *s1, const char *name, Section *sec, addr_t offs)
{ {
@ -1506,7 +1506,7 @@ ST_FUNC void tcc_add_btstub(TCCState *s1)
cstr_free(&cstr); cstr_free(&cstr);
set_local_sym(s1, &"___rt_info"[!s1->leading_underscore], s, o); set_local_sym(s1, &"___rt_info"[!s1->leading_underscore], s, o);
} }
#endif #endif /* def CONFIG_TCC_BACKTRACE */
static void tcc_tcov_add_file(TCCState *s1, const char *filename) static void tcc_tcov_add_file(TCCState *s1, const char *filename)
{ {
@ -1615,7 +1615,7 @@ ST_FUNC void tcc_add_runtime(TCCState *s1)
#endif #endif
} }
} }
#endif #endif /* ndef TCC_TARGET_PE */
/* add various standard linker symbols (must be done after the /* add various standard linker symbols (must be done after the
sections are filled (for example after allocating common sections are filled (for example after allocating common
@ -1688,7 +1688,6 @@ ST_FUNC void resolve_common_syms(TCCState *s1)
} }
#ifndef ELF_OBJ_ONLY #ifndef ELF_OBJ_ONLY
ST_FUNC void fill_got_entry(TCCState *s1, ElfW_Rel *rel) ST_FUNC void fill_got_entry(TCCState *s1, ElfW_Rel *rel)
{ {
int sym_index = ELFW(R_SYM) (rel->r_info); int sym_index = ELFW(R_SYM) (rel->r_info);
@ -3771,7 +3770,7 @@ static int ld_add_file(TCCState *s1, const char filename[])
static int ld_add_file_list(TCCState *s1, const char *cmd, int as_needed) static int ld_add_file_list(TCCState *s1, const char *cmd, int as_needed)
{ {
char filename[1024], libname[1016]; char filename[1024], libname[1024];
int t, group, nblibs = 0, ret = 0; int t, group, nblibs = 0, ret = 0;
char **libs = NULL; char **libs = NULL;

View file

@ -1380,7 +1380,7 @@ static void tcc_debug_fix_anon(CType *t)
if ((t->t & VT_BTYPE) == VT_STRUCT && t->ref->c != -1) if ((t->t & VT_BTYPE) == VT_STRUCT && t->ref->c != -1)
for (i = 0; i < n_debug_anon_hash; i++) for (i = 0; i < n_debug_anon_hash; i++)
if (t->ref == debug_anon_hash[i].type) { if (t->ref == debug_anon_hash[i].type) {
Sym sym = { .type = *t }; Sym sym = {0}; sym .type = *t ;
debug_type = tcc_get_dwarf_info(s1, &sym); debug_type = tcc_get_dwarf_info(s1, &sym);
for (j = 0; j < debug_anon_hash[i].n_debug_type; j++) for (j = 0; j < debug_anon_hash[i].n_debug_type; j++)
@ -1628,8 +1628,7 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s)
debug_type = tcc_debug_find(t, 1); debug_type = tcc_debug_find(t, 1);
if (debug_type == -1) { if (debug_type == -1) {
int pos_sib, pos_type; int pos_sib, pos_type;
CType ct = { VT_INT | (type & VT_UNSIGNED) , NULL }; Sym sym = {0}; sym .type.t = VT_INT | (type & VT_UNSIGNED) ;
Sym sym = { .type = ct };
pos_type = tcc_get_dwarf_info(s1, &sym); pos_type = tcc_get_dwarf_info(s1, &sym);
debug_type = tcc_debug_add(t, 1); debug_type = tcc_debug_add(t, 1);
@ -1705,8 +1704,7 @@ static int tcc_get_dwarf_info(TCCState *s1, Sym *s)
} }
else if (type == (VT_PTR | VT_ARRAY)) { else if (type == (VT_PTR | VT_ARRAY)) {
int sib_pos, sub_type; int sib_pos, sub_type;
CType ct = { VT_INT | VT_UNSIGNED , NULL }; Sym sym = {0}; sym .type.t = VT_INT | VT_UNSIGNED ;
Sym sym = { .type = ct };
sub_type = tcc_get_dwarf_info(s1, &sym); sub_type = tcc_get_dwarf_info(s1, &sym);
i = dwarf_info_section->data_offset; i = dwarf_info_section->data_offset;

View file

@ -262,8 +262,7 @@ static void * add_lc(struct macho *mo, uint32_t cmd, uint32_t cmdsize)
static struct segment_command_64 * add_segment(struct macho *mo, const char *name) static struct segment_command_64 * add_segment(struct macho *mo, const char *name)
{ {
struct segment_command_64 *sc = add_lc(mo, LC_SEGMENT_64, sizeof(*sc)); struct segment_command_64 *sc = add_lc(mo, LC_SEGMENT_64, sizeof(*sc));
strncpy(sc->segname, name, 16-1); strncpy(sc->segname, name, 16);
sc->segname[16-1] = '\0';
mo->seg2lc[mo->nseg++] = mo->nlc - 1; mo->seg2lc[mo->nseg++] = mo->nlc - 1;
return sc; return sc;
} }
@ -283,8 +282,7 @@ static int add_section(struct macho *mo, struct segment_command_64 **_seg, const
seg = tcc_realloc(seg, sizeof(*seg) + seg->nsects * sizeof(*sec)); seg = tcc_realloc(seg, sizeof(*seg) + seg->nsects * sizeof(*sec));
sec = (struct section_64*)((char*)seg + sizeof(*seg)) + ret; sec = (struct section_64*)((char*)seg + sizeof(*seg)) + ret;
memset(sec, 0, sizeof(*sec)); memset(sec, 0, sizeof(*sec));
strncpy(sec->sectname, name, 16-1); strncpy(sec->sectname, name, 16);
sec->sectname[16-1] = '\0';
strncpy(sec->segname, seg->segname, 16); strncpy(sec->segname, seg->segname, 16);
*_seg = seg; *_seg = seg;
return ret; return ret;

14
tccpp.c
View file

@ -2038,10 +2038,14 @@ include_done:
if (tok == TOK_STR) { if (tok == TOK_STR) {
if (file->true_filename == file->filename) if (file->true_filename == file->filename)
file->true_filename = tcc_strdup(file->filename); file->true_filename = tcc_strdup(file->filename);
/* prepend directory from real file */ q = (char *)tokc.str.data;
pstrcpy(buf, sizeof buf, file->true_filename); buf[0] = 0;
*tcc_basename(buf) = 0; if (!IS_ABSPATH(q)) {
pstrcat(buf, sizeof buf, (char *)tokc.str.data); /* prepend directory from real file */
pstrcpy(buf, sizeof buf, file->true_filename);
*tcc_basename(buf) = 0;
}
pstrcat(buf, sizeof buf, q);
tcc_debug_putfile(s1, buf); tcc_debug_putfile(s1, buf);
} else if (parse_flags & PARSE_FLAG_ASM_FILE) } else if (parse_flags & PARSE_FLAG_ASM_FILE)
break; break;
@ -3733,8 +3737,6 @@ static void tcc_predefs(TCCState *s1, CString *cs, int is_asm)
putdef(cs, "__CHAR_UNSIGNED__"); putdef(cs, "__CHAR_UNSIGNED__");
if (s1->optimize > 0) if (s1->optimize > 0)
putdef(cs, "__OPTIMIZE__"); putdef(cs, "__OPTIMIZE__");
if (s1->optimize == 's')
putdef(cs, "__OPTIMIZE_SIZE__");
if (s1->option_pthread) if (s1->option_pthread)
putdef(cs, "_REENTRANT"); putdef(cs, "_REENTRANT");
if (s1->leading_underscore) if (s1->leading_underscore)

View file

@ -5,7 +5,7 @@
TOP = .. TOP = ..
include $(TOP)/Makefile include $(TOP)/Makefile
VPATH = $(TOPSRC)/tests $(TOPSRC) $(TOP) VPATH = $(TOPSRC)/tests $(TOPSRC) $(TOP)
CFLAGS := $(filter-out -W% -g% -O%,$(CFLAGS)) -I$(TOPSRC) $(LDFLAGS) CFLAGS := $(filter-out -g% -O%,$(CFLAGS)) -I$(TOPSRC) $(LDFLAGS)
# what tests to run # what tests to run
TESTS = \ TESTS = \

View file

@ -23,7 +23,7 @@
#include "tcc.h" #include "tcc.h"
#if !defined(ELF_OBJ_ONLY) || defined(TCC_TARGET_MACHO) #ifdef NEED_RELOC_TYPE
/* Returns 1 for a code relocation, 0 for a data relocation. For unknown /* Returns 1 for a code relocation, 0 for a data relocation. For unknown
relocations, returns -1. */ relocations, returns -1. */
int code_reloc (int reloc_type) int code_reloc (int reloc_type)
@ -109,7 +109,7 @@ int gotplt_entry_type (int reloc_type)
return -1; return -1;
} }
#if !defined(TCC_TARGET_MACHO) || defined TCC_IS_NATIVE #ifdef NEED_BUILD_GOT
ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr) ST_FUNC unsigned create_plt_entry(TCCState *s1, unsigned got_offset, struct sym_attr *attr)
{ {
Section *plt = s1->plt; Section *plt = s1->plt;