History

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.

Thomas Preud'homme committed 9 years ago

Commit 59391d51 parent 097cf3a12 files · +129 −90Browse files

Unified · Split

12 files
  1. arm-gen.c +0 −20
  2. arm-link.c +28 −2
  3. arm64-gen.c +0 −14
  4. arm64-link.c +22 −2
  5. c67-gen.c +0 −15
  6. c67-link.c +22 −1
  7. elf.h +5 −1
  8. i386-gen.c +0 −15
  9. i386-link.c +23 −2
  10. tcc.h +6 −1
  11. x86_64-gen.c +0 −15
  12. x86_64-link.c +23 −2
arm-gen.c+0−20
@@ -129,26 +129,6 @@ enum { · 128 unmodified lines
129 129
130#define CHAR_IS_UNSIGNED130#define CHAR_IS_UNSIGNED
131 131
132/******************************************************/
133/* ELF defines */
134
135#define EM_TCC_TARGET EM_ARM
136
137/* relocation type for 32 bit data relocation */
138#define R_DATA_32 R_ARM_ABS32
139#define R_DATA_PTR R_ARM_ABS32
140#define R_JMP_SLOT R_ARM_JUMP_SLOT
141#define R_GLOB_DAT R_ARM_GLOB_DAT
142#define R_COPY R_ARM_COPY
143
144#define ELF_START_ADDR 0x00008000
145#define ELF_PAGE_SIZE 0x1000
146
147enum float_abi {
148 ARM_SOFTFP_FLOAT,
149 ARM_HARD_FLOAT,
150};
151
152/******************************************************/132/******************************************************/
153#else /* ! TARGET_DEFS_ONLY */133#else /* ! TARGET_DEFS_ONLY */
154/******************************************************/134/******************************************************/
arm-link.c+28−2
@@ -1,7 +1,31 @@
1#include "tcc.h"1#ifdef TARGET_DEFS_ONLY
2
3#define EM_TCC_TARGET EM_ARM
4
5/* relocation type for 32 bit data relocation */
6#define R_DATA_32 R_ARM_ABS32
7#define R_DATA_PTR R_ARM_ABS32
8#define R_JMP_SLOT R_ARM_JUMP_SLOT
9#define R_GLOB_DAT R_ARM_GLOB_DAT
10#define R_COPY R_ARM_COPY
11
12#define R_NUM R_ARM_NUM
13
14#define ELF_START_ADDR 0x00008000
15#define ELF_PAGE_SIZE 0x1000
16
2#define HAVE_SECTION_RELOC17#define HAVE_SECTION_RELOC
3 18
4ST_DATA struct reloc_info relocs_info[] = {19enum float_abi {
20 ARM_SOFTFP_FLOAT,
21 ARM_HARD_FLOAT,
22};
23
24#else /* !TARGET_DEFS_ONLY */
25
26#include "tcc.h"
27
28ST_DATA struct reloc_info relocs_info[R_NUM] = {
5 INIT_RELOC_INFO (R_ARM_PC24, 1, AUTO_GOTPLT_ENTRY, 0)29 INIT_RELOC_INFO (R_ARM_PC24, 1, AUTO_GOTPLT_ENTRY, 0)
6 INIT_RELOC_INFO (R_ARM_CALL, 1, AUTO_GOTPLT_ENTRY, 0)30 INIT_RELOC_INFO (R_ARM_CALL, 1, AUTO_GOTPLT_ENTRY, 0)
7 INIT_RELOC_INFO (R_ARM_JUMP24, 1, AUTO_GOTPLT_ENTRY, 0)31 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 · 240 unmodified lines
248 return;272 return;
249 }273 }
250}274}
275
276#endif /* !TARGET_DEFS_ONLY */
arm64-gen.c+0−14
@@ -40,20 +40,6 @@ · 39 unmodified lines
40 40
41#define CHAR_IS_UNSIGNED41#define CHAR_IS_UNSIGNED
42 42
43/******************************************************/
44/* ELF defines */
45
46#define EM_TCC_TARGET EM_AARCH64
47
48#define R_DATA_32 R_AARCH64_ABS32
49#define R_DATA_PTR R_AARCH64_ABS64
50#define R_JMP_SLOT R_AARCH64_JUMP_SLOT
51#define R_GLOB_DAT R_AARCH64_GLOB_DAT
52#define R_COPY R_AARCH64_COPY
53
54#define ELF_START_ADDR 0x00400000
55#define ELF_PAGE_SIZE 0x1000
56
57/******************************************************/43/******************************************************/
58#else /* ! TARGET_DEFS_ONLY */44#else /* ! TARGET_DEFS_ONLY */
59/******************************************************/45/******************************************************/
arm64-link.c+22−2
@@ -1,7 +1,25 @@
1#include "tcc.h"1#ifdef TARGET_DEFS_ONLY
2
3#define EM_TCC_TARGET EM_AARCH64
4
5#define R_DATA_32 R_AARCH64_ABS32
6#define R_DATA_PTR R_AARCH64_ABS64
7#define R_JMP_SLOT R_AARCH64_JUMP_SLOT
8#define R_GLOB_DAT R_AARCH64_GLOB_DAT
9#define R_COPY R_AARCH64_COPY
10
11#define R_NUM R_AARCH64_NUM
12
13#define ELF_START_ADDR 0x00400000
14#define ELF_PAGE_SIZE 0x1000
15
2#define HAVE_SECTION_RELOC16#define HAVE_SECTION_RELOC
3 17
4ST_DATA struct reloc_info relocs_info[] = {18#else /* !TARGET_DEFS_ONLY */
19
20#include "tcc.h"
21
22ST_DATA struct reloc_info relocs_info[R_NUM] = {
5 INIT_RELOC_INFO (R_AARCH64_ABS32, 0, NO_GOTPLT_ENTRY, 0)23 INIT_RELOC_INFO (R_AARCH64_ABS32, 0, NO_GOTPLT_ENTRY, 0)
6 INIT_RELOC_INFO (R_AARCH64_ABS64, 0, NO_GOTPLT_ENTRY, 0)24 INIT_RELOC_INFO (R_AARCH64_ABS64, 0, NO_GOTPLT_ENTRY, 0)
7 INIT_RELOC_INFO (R_AARCH64_MOVW_UABS_G0_NC, 0, NO_GOTPLT_ENTRY, 0)25 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 · 103 unmodified lines
111 return;129 return;
112 }130 }
113}131}
132
133#endif /* !TARGET_DEFS_ONLY */
c67-gen.c+0−15
@@ -108,21 +108,6 @@ enum { · 107 unmodified lines
108/* maximum alignment (for aligned attribute support) */108/* maximum alignment (for aligned attribute support) */
109#define MAX_ALIGN 8109#define MAX_ALIGN 8
110 110
111/******************************************************/
112/* ELF defines */
113
114#define EM_TCC_TARGET EM_C60
115
116/* relocation type for 32 bit data relocation */
117#define R_DATA_32 R_C60_32
118#define R_DATA_PTR R_C60_32
119#define R_JMP_SLOT R_C60_JMP_SLOT
120#define R_GLOB_DAT R_C60_GLOB_DAT
121#define R_COPY R_C60_COPY
122
123#define ELF_START_ADDR 0x00000400
124#define ELF_PAGE_SIZE 0x1000
125
126/******************************************************/111/******************************************************/
127#else /* ! TARGET_DEFS_ONLY */112#else /* ! TARGET_DEFS_ONLY */
128/******************************************************/113/******************************************************/
c67-link.c+22−1
@@ -1,6 +1,25 @@
1#include "tcc.h"1#ifdef TARGET_DEFS_ONLY
2
3#define EM_TCC_TARGET EM_C60
4
5/* relocation type for 32 bit data relocation */
6#define R_DATA_32 R_C60_32
7#define R_DATA_PTR R_C60_32
8#define R_JMP_SLOT R_C60_JMP_SLOT
9#define R_GLOB_DAT R_C60_GLOB_DAT
10#define R_COPY R_C60_COPY
11
12#define R_NUM R_C60_NUM
13
14#define ELF_START_ADDR 0x00000400
15#define ELF_PAGE_SIZE 0x1000
16
2#define HAVE_SECTION_RELOC17#define HAVE_SECTION_RELOC
3 18
19#else /* !TARGET_DEFS_ONLY */
20
21#include "tcc.h"
22
4void relocate_init(Section *sr) {}23void relocate_init(Section *sr) {}
5 24
6void relocate(TCCState *s1, ElfW_Rel *rel, int type, char *ptr, addr_t addr, addr_t val)25void 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 · 26 unmodified lines
33 break;52 break;
34 }53 }
35}54}
55
56#endif /* !TARGET_DEFS_ONLY */
elf.h+5−1
@@ -2456,6 +2456,8 @@ typedef Elf32_Addr Elf32_Conflict; · 2455 unmodified lines
2456#define R_AARCH64_TLS_TPREL64 1030 /* TP-relative offset, 64 bit. */2456#define R_AARCH64_TLS_TPREL64 1030 /* TP-relative offset, 64 bit. */
2457#define R_AARCH64_TLSDESC 1031 /* TLS Descriptor. */2457#define R_AARCH64_TLSDESC 1031 /* TLS Descriptor. */
2458#define R_AARCH64_IRELATIVE 1032 /* STT_GNU_IFUNC relocation. */2458#define R_AARCH64_IRELATIVE 1032 /* STT_GNU_IFUNC relocation. */
2459/* Keep this the last entry. */
2460#define R_AARCH64_NUM 1033
2459 2461
2460/* ARM relocs. */2462/* ARM relocs. */
2461 2463
@@ -2547,6 +2549,8 @@ typedef Elf32_Addr Elf32_Conflict; · 85 unmodified lines
2547#define R_C60_RELATIVE 8 /* Adjust by program base */2549#define R_C60_RELATIVE 8 /* Adjust by program base */
2548#define R_C60_GOTOFF 9 /* 32 bit offset to GOT */2550#define R_C60_GOTOFF 9 /* 32 bit offset to GOT */
2549#define R_C60_GOTPC 10 /* 32 bit PC relative offset to GOT */2551#define R_C60_GOTPC 10 /* 32 bit PC relative offset to GOT */
2552/* Keep this the last entry. */
2553#define R_C60_NUM 11
2550 2554
2551#define R_C60HI16 0x55 /* high 16 bit MVKH embedded */2555#define R_C60HI16 0x55 /* high 16 bit MVKH embedded */
2552#define R_C60LO16 0x54 /* low 16 bit MVKL embedded */2556#define R_C60LO16 0x54 /* low 16 bit MVKL embedded */
@@ -2900,7 +2904,7 @@ typedef Elf32_Addr Elf32_Conflict; · 347 unmodified lines
2900#define R_X86_64_REX_GOTPCRELX 42 /* like GOTPCRELX, but a REX prefix2904#define R_X86_64_REX_GOTPCRELX 42 /* like GOTPCRELX, but a REX prefix
2901 is present */2905 is present */
2902 2906
2903#define R_X86_64_NUM 392907#define R_X86_64_NUM 43
2904 2908
2905 2909
2906/* AM33 relocations. */2910/* AM33 relocations. */
i386-gen.c+0−15
@@ -73,21 +73,6 @@ enum { · 72 unmodified lines
73 73
74#define psym oad74#define psym oad
75 75
76/******************************************************/
77/* ELF defines */
78
79#define EM_TCC_TARGET EM_386
80
81/* relocation type for 32 bit data relocation */
82#define R_DATA_32 R_386_32
83#define R_DATA_PTR R_386_32
84#define R_JMP_SLOT R_386_JMP_SLOT
85#define R_GLOB_DAT R_386_GLOB_DAT
86#define R_COPY R_386_COPY
87
88#define ELF_START_ADDR 0x08048000
89#define ELF_PAGE_SIZE 0x1000
90
91/******************************************************/76/******************************************************/
92#else /* ! TARGET_DEFS_ONLY */77#else /* ! TARGET_DEFS_ONLY */
93/******************************************************/78/******************************************************/
i386-link.c+23−2
@@ -1,8 +1,27 @@
1#include "tcc.h"1#ifdef TARGET_DEFS_ONLY
2
3#define EM_TCC_TARGET EM_386
4
5/* relocation type for 32 bit data relocation */
6#define R_DATA_32 R_386_32
7#define R_DATA_PTR R_386_32
8#define R_JMP_SLOT R_386_JMP_SLOT
9#define R_GLOB_DAT R_386_GLOB_DAT
10#define R_COPY R_386_COPY
11
12#define R_NUM R_386_NUM
13
14#define ELF_START_ADDR 0x08048000
15#define ELF_PAGE_SIZE 0x1000
16
2#define HAVE_SECTION_RELOC17#define HAVE_SECTION_RELOC
3 18
19#else /* !TARGET_DEFS_ONLY */
20
21#include "tcc.h"
22
4static ElfW_Rel *qrel; /* ptr to next reloc entry reused */23static ElfW_Rel *qrel; /* ptr to next reloc entry reused */
5ST_DATA struct reloc_info relocs_info[] = {24ST_DATA struct reloc_info relocs_info[R_NUM] = {
6 INIT_RELOC_INFO (R_386_32, 0, NO_GOTPLT_ENTRY, 0)25 INIT_RELOC_INFO (R_386_32, 0, NO_GOTPLT_ENTRY, 0)
7 INIT_RELOC_INFO (R_386_PC32, 1, AUTO_GOTPLT_ENTRY, 0)26 INIT_RELOC_INFO (R_386_PC32, 1, AUTO_GOTPLT_ENTRY, 0)
8 INIT_RELOC_INFO (R_386_PLT32, 1, ALWAYS_GOTPLT_ENTRY, 0)27 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 · 92 unmodified lines
101 return;120 return;
102 }121 }
103}122}
123
124#endif /* !TARGET_DEFS_ONLY */
tcc.h+6−1
@@ -290,19 +290,24 @@ · 289 unmodified lines
290#define TARGET_DEFS_ONLY290#define TARGET_DEFS_ONLY
291#ifdef TCC_TARGET_I386291#ifdef TCC_TARGET_I386
292# include "i386-gen.c"292# include "i386-gen.c"
293# include "i386-link.c"
293#endif294#endif
294#ifdef TCC_TARGET_X86_64295#ifdef TCC_TARGET_X86_64
295# include "x86_64-gen.c"296# include "x86_64-gen.c"
297# include "x86_64-link.c"
296#endif298#endif
297#ifdef TCC_TARGET_ARM299#ifdef TCC_TARGET_ARM
298# include "arm-gen.c"300# include "arm-gen.c"
301# include "arm-link.c"
299#endif302#endif
300#ifdef TCC_TARGET_ARM64303#ifdef TCC_TARGET_ARM64
301# include "arm64-gen.c"304# include "arm64-gen.c"
305# include "arm64-link.c"
302#endif306#endif
303#ifdef TCC_TARGET_C67307#ifdef TCC_TARGET_C67
304# include "coff.h"308# include "coff.h"
305# include "c67-gen.c"309# include "c67-gen.c"
310# include "c67-link.c"
306#endif311#endif
307#undef TARGET_DEFS_ONLY312#undef TARGET_DEFS_ONLY
308 313
@@ -1325,7 +1330,7 @@ struct reloc_info { · 1016 unmodified lines
1325 1330
1326#define INIT_RELOC_INFO(rtype, code_reloc, gotplt_entry, pltoff_addend) \1331#define INIT_RELOC_INFO(rtype, code_reloc, gotplt_entry, pltoff_addend) \
1327 [rtype] = {code_reloc, gotplt_entry, pltoff_addend},1332 [rtype] = {code_reloc, gotplt_entry, pltoff_addend},
1328ST_DATA struct reloc_info relocs_info[];1333ST_DATA struct reloc_info relocs_info[R_NUM];
1329 1334
1330ST_DATA Section *text_section, *data_section, *bss_section; /* predefined sections */1335ST_DATA Section *text_section, *data_section, *bss_section; /* predefined sections */
1331ST_DATA Section *cur_text_section; /* current section where function code is generated */1336ST_DATA Section *cur_text_section; /* current section where function code is generated */
x86_64-gen.c+0−15
@@ -101,21 +101,6 @@ enum { · 100 unmodified lines
101/* maximum alignment (for aligned attribute support) */101/* maximum alignment (for aligned attribute support) */
102#define MAX_ALIGN 16102#define MAX_ALIGN 16
103 103
104/******************************************************/
105/* ELF defines */
106
107#define EM_TCC_TARGET EM_X86_64
108
109/* relocation type for 32 bit data relocation */
110#define R_DATA_32 R_X86_64_32
111#define R_DATA_PTR R_X86_64_64
112#define R_JMP_SLOT R_X86_64_JUMP_SLOT
113#define R_GLOB_DAT R_X86_64_GLOB_DAT
114#define R_COPY R_X86_64_COPY
115
116#define ELF_START_ADDR 0x400000
117#define ELF_PAGE_SIZE 0x200000
118
119/******************************************************/104/******************************************************/
120#else /* ! TARGET_DEFS_ONLY */105#else /* ! TARGET_DEFS_ONLY */
121/******************************************************/106/******************************************************/
x86_64-link.c+23−2
@@ -1,8 +1,27 @@
1#include "tcc.h"1#ifdef TARGET_DEFS_ONLY
2
3#define EM_TCC_TARGET EM_X86_64
4
5/* relocation type for 32 bit data relocation */
6#define R_DATA_32 R_X86_64_32
7#define R_DATA_PTR R_X86_64_64
8#define R_JMP_SLOT R_X86_64_JUMP_SLOT
9#define R_GLOB_DAT R_X86_64_GLOB_DAT
10#define R_COPY R_X86_64_COPY
11
12#define R_NUM R_X86_64_NUM
13
14#define ELF_START_ADDR 0x400000
15#define ELF_PAGE_SIZE 0x200000
16
2#define HAVE_SECTION_RELOC17#define HAVE_SECTION_RELOC
3 18
19#else /* !TARGET_DEFS_ONLY */
20
21#include "tcc.h"
22
4static ElfW_Rel *qrel; /* ptr to next reloc entry reused */23static ElfW_Rel *qrel; /* ptr to next reloc entry reused */
5ST_DATA struct reloc_info relocs_info[] = {24ST_DATA struct reloc_info relocs_info[R_NUM] = {
6 INIT_RELOC_INFO (R_X86_64_64, 0, AUTO_GOTPLT_ENTRY, 0)25 INIT_RELOC_INFO (R_X86_64_64, 0, AUTO_GOTPLT_ENTRY, 0)
7 INIT_RELOC_INFO (R_X86_64_32, 0, AUTO_GOTPLT_ENTRY, 0)26 INIT_RELOC_INFO (R_X86_64_32, 0, AUTO_GOTPLT_ENTRY, 0)
8 INIT_RELOC_INFO (R_X86_64_32S, 0, AUTO_GOTPLT_ENTRY, 0)27 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 · 98 unmodified lines
107 break;126 break;
108 }127 }
109}128}
129
130#endif /* !TARGET_DEFS_ONLY */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t