From 59391d5520534ef1fe3cc2e96fa567c870e2f533 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Mon, 5 Dec 2016 20:40:59 +0000 Subject: [PATCH] Fix relocs_info declaration in tcc.h C standard specifies that array should be declared with a non null size or with * for standard array. Declaration of relocs_info in tcc.h was not respecting this rule. This commit add a R_NUM macro that maps to the R__NUM macros and declare relocs_info using it. This commit also moves all linker-related macros from -gen.c files to -link.c ones. --- arm-gen.c | 20 -------------------- arm-link.c | 30 ++++++++++++++++++++++++++++-- arm64-gen.c | 14 -------------- arm64-link.c | 24 ++++++++++++++++++++++-- c67-gen.c | 15 --------------- c67-link.c | 23 ++++++++++++++++++++++- elf.h | 6 +++++- i386-gen.c | 15 --------------- i386-link.c | 25 +++++++++++++++++++++++-- tcc.h | 7 ++++++- x86_64-gen.c | 15 --------------- x86_64-link.c | 25 +++++++++++++++++++++++-- 12 files changed, 129 insertions(+), 90 deletions(-) diff --git a/arm-gen.c b/arm-gen.c index 2c30daee..cf3ea959 100644 --- a/arm-gen.c +++ b/arm-gen.c @@ -130,26 +130,6 @@ enum { #define CHAR_IS_UNSIGNED /******************************************************/ -/* ELF defines */ - -#define EM_TCC_TARGET EM_ARM - -/* relocation type for 32 bit data relocation */ -#define R_DATA_32 R_ARM_ABS32 -#define R_DATA_PTR R_ARM_ABS32 -#define R_JMP_SLOT R_ARM_JUMP_SLOT -#define R_GLOB_DAT R_ARM_GLOB_DAT -#define R_COPY R_ARM_COPY - -#define ELF_START_ADDR 0x00008000 -#define ELF_PAGE_SIZE 0x1000 - -enum float_abi { - ARM_SOFTFP_FLOAT, - ARM_HARD_FLOAT, -}; - -/******************************************************/ #else /* ! TARGET_DEFS_ONLY */ /******************************************************/ #include "tcc.h" diff --git a/arm-link.c b/arm-link.c index 396c2c0b..02f8196a 100644 --- a/arm-link.c +++ b/arm-link.c @@ -1,7 +1,31 @@ -#include "tcc.h" +#ifdef TARGET_DEFS_ONLY + +#define EM_TCC_TARGET EM_ARM + +/* relocation type for 32 bit data relocation */ +#define R_DATA_32 R_ARM_ABS32 +#define R_DATA_PTR R_ARM_ABS32 +#define R_JMP_SLOT R_ARM_JUMP_SLOT +#define R_GLOB_DAT R_ARM_GLOB_DAT +#define R_COPY R_ARM_COPY + +#define R_NUM R_ARM_NUM + +#define ELF_START_ADDR 0x00008000 +#define ELF_PAGE_SIZE 0x1000 + #define HAVE_SECTION_RELOC -ST_DATA struct reloc_info relocs_info[] = { +enum float_abi { + ARM_SOFTFP_FLOAT, + ARM_HARD_FLOAT, +}; + +#else /* !TARGET_DEFS_ONLY */ + +#include "tcc.h" + +ST_DATA struct reloc_info relocs_info[R_NUM] = { INIT_RELOC_INFO (R_ARM_PC24, 1, AUTO_GOTPLT_ENTRY, 0) INIT_RELOC_INFO (R_ARM_CALL, 1, AUTO_GOTPLT_ENTRY, 0) INIT_RELOC_INFO (R_ARM_JUMP24, 1, AUTO_GOTPLT_ENTRY, 0) @@ -248,3 +272,5 @@ void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, add return; } } + +#endif /* !TARGET_DEFS_ONLY */ diff --git a/arm64-gen.c b/arm64-gen.c index c4e83e15..5bb8e244 100644 --- a/arm64-gen.c +++ b/arm64-gen.c @@ -41,20 +41,6 @@ #define CHAR_IS_UNSIGNED /******************************************************/ -/* ELF defines */ - -#define EM_TCC_TARGET EM_AARCH64 - -#define R_DATA_32 R_AARCH64_ABS32 -#define R_DATA_PTR R_AARCH64_ABS64 -#define R_JMP_SLOT R_AARCH64_JUMP_SLOT -#define R_GLOB_DAT R_AARCH64_GLOB_DAT -#define R_COPY R_AARCH64_COPY - -#define ELF_START_ADDR 0x00400000 -#define ELF_PAGE_SIZE 0x1000 - -/******************************************************/ #else /* ! TARGET_DEFS_ONLY */ /******************************************************/ #include "tcc.h" diff --git a/arm64-link.c b/arm64-link.c index 581f1ee5..c2842d4e 100644 --- a/arm64-link.c +++ b/arm64-link.c @@ -1,7 +1,25 @@ -#include "tcc.h" +#ifdef TARGET_DEFS_ONLY + +#define EM_TCC_TARGET EM_AARCH64 + +#define R_DATA_32 R_AARCH64_ABS32 +#define R_DATA_PTR R_AARCH64_ABS64 +#define R_JMP_SLOT R_AARCH64_JUMP_SLOT +#define R_GLOB_DAT R_AARCH64_GLOB_DAT +#define R_COPY R_AARCH64_COPY + +#define R_NUM R_AARCH64_NUM + +#define ELF_START_ADDR 0x00400000 +#define ELF_PAGE_SIZE 0x1000 + #define HAVE_SECTION_RELOC -ST_DATA struct reloc_info relocs_info[] = { +#else /* !TARGET_DEFS_ONLY */ + +#include "tcc.h" + +ST_DATA struct reloc_info relocs_info[R_NUM] = { INIT_RELOC_INFO (R_AARCH64_ABS32, 0, NO_GOTPLT_ENTRY, 0) INIT_RELOC_INFO (R_AARCH64_ABS64, 0, NO_GOTPLT_ENTRY, 0) INIT_RELOC_INFO (R_AARCH64_MOVW_UABS_G0_NC, 0, NO_GOTPLT_ENTRY, 0) @@ -111,3 +129,5 @@ void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, add return; } } + +#endif /* !TARGET_DEFS_ONLY */ diff --git a/c67-gen.c b/c67-gen.c index fcfc23c1..28db68b2 100644 --- a/c67-gen.c +++ b/c67-gen.c @@ -109,21 +109,6 @@ enum { #define MAX_ALIGN 8 /******************************************************/ -/* ELF defines */ - -#define EM_TCC_TARGET EM_C60 - -/* relocation type for 32 bit data relocation */ -#define R_DATA_32 R_C60_32 -#define R_DATA_PTR R_C60_32 -#define R_JMP_SLOT R_C60_JMP_SLOT -#define R_GLOB_DAT R_C60_GLOB_DAT -#define R_COPY R_C60_COPY - -#define ELF_START_ADDR 0x00000400 -#define ELF_PAGE_SIZE 0x1000 - -/******************************************************/ #else /* ! TARGET_DEFS_ONLY */ /******************************************************/ #include "tcc.h" diff --git a/c67-link.c b/c67-link.c index d8b0f7e8..960b34b7 100644 --- a/c67-link.c +++ b/c67-link.c @@ -1,6 +1,25 @@ -#include "tcc.h" +#ifdef TARGET_DEFS_ONLY + +#define EM_TCC_TARGET EM_C60 + +/* relocation type for 32 bit data relocation */ +#define R_DATA_32 R_C60_32 +#define R_DATA_PTR R_C60_32 +#define R_JMP_SLOT R_C60_JMP_SLOT +#define R_GLOB_DAT R_C60_GLOB_DAT +#define R_COPY R_C60_COPY + +#define R_NUM R_C60_NUM + +#define ELF_START_ADDR 0x00000400 +#define ELF_PAGE_SIZE 0x1000 + #define HAVE_SECTION_RELOC +#else /* !TARGET_DEFS_ONLY */ + +#include "tcc.h" + void relocate_init(Section *sr) {} void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val) @@ -33,3 +52,5 @@ void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, add break; } } + +#endif /* !TARGET_DEFS_ONLY */ diff --git a/elf.h b/elf.h index ecabafa9..3d0976b0 100644 --- a/elf.h +++ b/elf.h @@ -2456,6 +2456,8 @@ typedef Elf32_Addr Elf32_Conflict; #define R_AARCH64_TLS_TPREL64 1030 /* TP-relative offset, 64 bit. */ #define R_AARCH64_TLSDESC 1031 /* TLS Descriptor. */ #define R_AARCH64_IRELATIVE 1032 /* STT_GNU_IFUNC relocation. */ +/* Keep this the last entry. */ +#define R_AARCH64_NUM 1033 /* ARM relocs. */ @@ -2547,6 +2549,8 @@ typedef Elf32_Addr Elf32_Conflict; #define R_C60_RELATIVE 8 /* Adjust by program base */ #define R_C60_GOTOFF 9 /* 32 bit offset to GOT */ #define R_C60_GOTPC 10 /* 32 bit PC relative offset to GOT */ +/* Keep this the last entry. */ +#define R_C60_NUM 11 #define R_C60HI16 0x55 /* high 16 bit MVKH embedded */ #define R_C60LO16 0x54 /* low 16 bit MVKL embedded */ @@ -2900,7 +2904,7 @@ typedef Elf32_Addr Elf32_Conflict; #define R_X86_64_REX_GOTPCRELX 42 /* like GOTPCRELX, but a REX prefix is present */ -#define R_X86_64_NUM 39 +#define R_X86_64_NUM 43 /* AM33 relocations. */ diff --git a/i386-gen.c b/i386-gen.c index 1d8ff197..ae40ca75 100644 --- a/i386-gen.c +++ b/i386-gen.c @@ -74,21 +74,6 @@ enum { #define psym oad /******************************************************/ -/* ELF defines */ - -#define EM_TCC_TARGET EM_386 - -/* relocation type for 32 bit data relocation */ -#define R_DATA_32 R_386_32 -#define R_DATA_PTR R_386_32 -#define R_JMP_SLOT R_386_JMP_SLOT -#define R_GLOB_DAT R_386_GLOB_DAT -#define R_COPY R_386_COPY - -#define ELF_START_ADDR 0x08048000 -#define ELF_PAGE_SIZE 0x1000 - -/******************************************************/ #else /* ! TARGET_DEFS_ONLY */ /******************************************************/ #include "tcc.h" diff --git a/i386-link.c b/i386-link.c index 019b53f3..c9724816 100644 --- a/i386-link.c +++ b/i386-link.c @@ -1,8 +1,27 @@ -#include "tcc.h" +#ifdef TARGET_DEFS_ONLY + +#define EM_TCC_TARGET EM_386 + +/* relocation type for 32 bit data relocation */ +#define R_DATA_32 R_386_32 +#define R_DATA_PTR R_386_32 +#define R_JMP_SLOT R_386_JMP_SLOT +#define R_GLOB_DAT R_386_GLOB_DAT +#define R_COPY R_386_COPY + +#define R_NUM R_386_NUM + +#define ELF_START_ADDR 0x08048000 +#define ELF_PAGE_SIZE 0x1000 + #define HAVE_SECTION_RELOC +#else /* !TARGET_DEFS_ONLY */ + +#include "tcc.h" + static ElfW_Rel *qrel; /* ptr to next reloc entry reused */ -ST_DATA struct reloc_info relocs_info[] = { +ST_DATA struct reloc_info relocs_info[R_NUM] = { INIT_RELOC_INFO (R_386_32, 0, NO_GOTPLT_ENTRY, 0) INIT_RELOC_INFO (R_386_PC32, 1, AUTO_GOTPLT_ENTRY, 0) INIT_RELOC_INFO (R_386_PLT32, 1, ALWAYS_GOTPLT_ENTRY, 0) @@ -101,3 +120,5 @@ void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, add return; } } + +#endif /* !TARGET_DEFS_ONLY */ diff --git a/tcc.h b/tcc.h index fbabd7a3..65858d0d 100644 --- a/tcc.h +++ b/tcc.h @@ -290,19 +290,24 @@ #define TARGET_DEFS_ONLY #ifdef TCC_TARGET_I386 # include "i386-gen.c" +# include "i386-link.c" #endif #ifdef TCC_TARGET_X86_64 # include "x86_64-gen.c" +# include "x86_64-link.c" #endif #ifdef TCC_TARGET_ARM # include "arm-gen.c" +# include "arm-link.c" #endif #ifdef TCC_TARGET_ARM64 # include "arm64-gen.c" +# include "arm64-link.c" #endif #ifdef TCC_TARGET_C67 # include "coff.h" # include "c67-gen.c" +# include "c67-link.c" #endif #undef TARGET_DEFS_ONLY @@ -1325,7 +1330,7 @@ struct reloc_info { #define INIT_RELOC_INFO(rtype, code_reloc, gotplt_entry, pltoff_addend) \ [rtype] = {code_reloc, gotplt_entry, pltoff_addend}, -ST_DATA struct reloc_info relocs_info[]; +ST_DATA struct reloc_info relocs_info[R_NUM]; ST_DATA Section *text_section, *data_section, *bss_section; /* predefined sections */ ST_DATA Section *cur_text_section; /* current section where function code is generated */ diff --git a/x86_64-gen.c b/x86_64-gen.c index f183b771..8a2d03a3 100644 --- a/x86_64-gen.c +++ b/x86_64-gen.c @@ -102,21 +102,6 @@ enum { #define MAX_ALIGN 16 /******************************************************/ -/* ELF defines */ - -#define EM_TCC_TARGET EM_X86_64 - -/* relocation type for 32 bit data relocation */ -#define R_DATA_32 R_X86_64_32 -#define R_DATA_PTR R_X86_64_64 -#define R_JMP_SLOT R_X86_64_JUMP_SLOT -#define R_GLOB_DAT R_X86_64_GLOB_DAT -#define R_COPY R_X86_64_COPY - -#define ELF_START_ADDR 0x400000 -#define ELF_PAGE_SIZE 0x200000 - -/******************************************************/ #else /* ! TARGET_DEFS_ONLY */ /******************************************************/ #include "tcc.h" diff --git a/x86_64-link.c b/x86_64-link.c index a5268654..8769b3a7 100644 --- a/x86_64-link.c +++ b/x86_64-link.c @@ -1,8 +1,27 @@ -#include "tcc.h" +#ifdef TARGET_DEFS_ONLY + +#define EM_TCC_TARGET EM_X86_64 + +/* relocation type for 32 bit data relocation */ +#define R_DATA_32 R_X86_64_32 +#define R_DATA_PTR R_X86_64_64 +#define R_JMP_SLOT R_X86_64_JUMP_SLOT +#define R_GLOB_DAT R_X86_64_GLOB_DAT +#define R_COPY R_X86_64_COPY + +#define R_NUM R_X86_64_NUM + +#define ELF_START_ADDR 0x400000 +#define ELF_PAGE_SIZE 0x200000 + #define HAVE_SECTION_RELOC +#else /* !TARGET_DEFS_ONLY */ + +#include "tcc.h" + static ElfW_Rel *qrel; /* ptr to next reloc entry reused */ -ST_DATA struct reloc_info relocs_info[] = { +ST_DATA struct reloc_info relocs_info[R_NUM] = { INIT_RELOC_INFO (R_X86_64_64, 0, AUTO_GOTPLT_ENTRY, 0) INIT_RELOC_INFO (R_X86_64_32, 0, AUTO_GOTPLT_ENTRY, 0) INIT_RELOC_INFO (R_X86_64_32S, 0, AUTO_GOTPLT_ENTRY, 0) @@ -107,3 +126,5 @@ void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, add break; } } + +#endif /* !TARGET_DEFS_ONLY */ -- 2.11.4.GIT