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_<ARCH>_NUM macros and declare relocs_info using it. This commit also
moves all linker-related macros from <arch>-gen.c files to <arch>-link.c
ones.
master
Thomas Preud'homme 2016-12-05 20:40:59 +00:00
parent 097cf3aa5e
commit 59391d5520
12 changed files with 129 additions and 90 deletions

View File

@ -129,26 +129,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 */
/******************************************************/

View File

@ -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 */

View File

@ -40,20 +40,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 */
/******************************************************/

View File

@ -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 */

View File

@ -108,21 +108,6 @@ enum {
/* maximum alignment (for aligned attribute support) */
#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 */
/******************************************************/

View File

@ -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 */

6
elf.h
View File

@ -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. */

View File

@ -73,21 +73,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 */
/******************************************************/

View File

@ -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 */

7
tcc.h
View File

@ -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 */

View File

@ -101,21 +101,6 @@ enum {
/* maximum alignment (for aligned attribute support) */
#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 */
/******************************************************/

View File

@ -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 */