aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Preud'homme <robotux@celest.fr>2016-12-05 20:40:59 +0000
committerThomas Preud'homme <robotux@celest.fr>2016-12-05 20:51:10 +0000
commit59391d5520534ef1fe3cc2e96fa567c870e2f533 (patch)
treeb1382b41c1a41310db148c9939f1792b621332d9
parent097cf3aa5ee370bab50d6d15cef9b0af55a1a3a2 (diff)
downloadtinycc-59391d5520534ef1fe3cc2e96fa567c870e2f533.tar.gz
tinycc-59391d5520534ef1fe3cc2e96fa567c870e2f533.tar.bz2
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.
-rw-r--r--arm-gen.c20
-rw-r--r--arm-link.c30
-rw-r--r--arm64-gen.c14
-rw-r--r--arm64-link.c24
-rw-r--r--c67-gen.c15
-rw-r--r--c67-link.c23
-rw-r--r--elf.h6
-rw-r--r--i386-gen.c15
-rw-r--r--i386-link.c25
-rw-r--r--tcc.h7
-rw-r--r--x86_64-gen.c15
-rw-r--r--x86_64-link.c25
12 files changed, 129 insertions, 90 deletions
diff --git a/arm-gen.c b/arm-gen.c
index 2c30dae..cf3ea95 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 396c2c0..02f8196 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 c4e83e1..5bb8e24 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 581f1ee..c2842d4 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 fcfc23c..28db68b 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 d8b0f7e..960b34b 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 ecabafa..3d0976b 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 1d8ff19..ae40ca7 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 019b53f..c972481 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 fbabd7a..65858d0 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 f183b77..8a2d03a 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 a526865..8769b3a 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 */