History

tccpe: cleanup ELFW() macros etc.

grischka committed 15 years ago

Commit aa80e5b1 parent d483ab35 files · +44 −59Browse files

Unified · Split

5 files
  1. elf.h +0 −10
  2. tcc.h +18 −0
  3. tccelf.c +1 −16
  4. tccpe.c +14 −32
  5. win32/tools/tiny_libmaker.c +11 −1
elf.h+0−10
@@ -1712,14 +1712,4 @@ typedef Elf32_Addr Elf32_Conflict; · 1711 unmodified lines
17121712 #define R_C60HI16 0x55 // high 16 bit MVKH embedded
17131713 #define R_C60LO16 0x54 // low 16 bit MVKL embedded
17141714
1715−#ifdef TCC_TARGET_X86_64
1716−#define TCC_ELFCLASS ELFCLASS64
1717−#define ElfW(type) Elf##64##_##type
1718−#define ELFW(type) ELF##64##_##type
1719−#else
1720−#define TCC_ELFCLASS ELFCLASS32
1721−#define ElfW(type) Elf##32##_##type
1722−#define ELFW(type) ELF##32##_##type
1723−#endif
1724−
17251715 #endif /* elf.h */
tcc.h+18−0
@@ -1150,6 +1150,24 @@ ST_INLN void inp(void); · 1149 unmodified lines
11501150 ST_FUNC int handle_eob(void);
11511151 #endif
11521152
1153+#ifdef TCC_TARGET_X86_64
1154+# define ELFCLASSW ELFCLASS64
1155+# define ElfW(type) Elf##64##_##type
1156+# define ELFW(type) ELF##64##_##type
1157+# define ElfW_Rel ElfW(Rela)
1158+# define SHT_RELX SHT_RELA
1159+# define REL_SECTION_FMT ".rela%s"
1160+/* XXX: DLL with PLT would only work with x86-64 for now */
1161+# define TCC_OUTPUT_DLL_WITH_PLT
1162+#else
1163+# define ELFCLASSW ELFCLASS32
1164+# define ElfW(type) Elf##32##_##type
1165+# define ELFW(type) ELF##32##_##type
1166+# define ElfW_Rel ElfW(Rel)
1167+# define SHT_RELX SHT_REL
1168+# define REL_SECTION_FMT ".rel%s"
1169+#endif
1170+
11531171 /* ------------ xxx-gen.c ------------ */
11541172
11551173 ST_FUNC void gsym_addr(int t, int a);
tccelf.c+1−16
@@ -20,23 +20,8 @@ · 19 unmodified lines
2020
2121 #include "tcc.h"
2222
23−#ifdef TCC_TARGET_X86_64
24−#define ElfW_Rel ElfW(Rela)
25−#define SHT_RELX SHT_RELA
26−#define REL_SECTION_FMT ".rela%s"
27−/* x86-64 requires PLT for DLLs */
28−#define TCC_OUTPUT_DLL_WITH_PLT
29−#else
30−#define ElfW_Rel ElfW(Rel)
31−#define SHT_RELX SHT_REL
32−#define REL_SECTION_FMT ".rel%s"
33−#endif
34−
3523 static int new_undef_sym = 0; /* Is there a new undefined sym since last new_undef_sym() */
3624
37−/* XXX: DLL with PLT would only work with x86-64 for now */
38−//#define TCC_OUTPUT_DLL_WITH_PLT
39−
4025 ST_FUNC int put_elf_str(Section *s, const char *sym)
4126 {
4227 int offset, len;
@@ -2119,7 +2104,7 @@ static int elf_output_file(TCCState *s1, const char *filename) · 2076 unmodified lines
21192104 ehdr.e_ident[1] = ELFMAG1;
21202105 ehdr.e_ident[2] = ELFMAG2;
21212106 ehdr.e_ident[3] = ELFMAG3;
2122− ehdr.e_ident[4] = TCC_ELFCLASS;
2107+ ehdr.e_ident[4] = ELFCLASSW;
21232108 ehdr.e_ident[5] = ELFDATA2LSB;
21242109 ehdr.e_ident[6] = EV_CURRENT;
21252110 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
tccpe.c+14−32
@@ -726,38 +726,20 @@ static int pe_write(struct pe_info *pe) · 725 unmodified lines
726726 /*----------------------------------------------------------------------------*/
727727
728728 #if defined(TCC_TARGET_X86_64)
729−#define ELFW_R_(type) ELF64_R_##type
730−#define ElfW_Rel ElfW(Rela)
731−
732729 #define REL_TYPE_DIRECT R_X86_64_64
733730 #define R_XXX_THUNKFIX R_X86_64_PC32
734731 #define R_XXX_RELATIVE R_X86_64_RELATIVE
735732
736−#define ELFW_ST_BIND ELF64_ST_BIND
737−#define ELFW_ST_TYPE ELF64_ST_TYPE
738−#define ELFW_ST_INFO ELF64_ST_INFO
739733 #elif defined(TCC_TARGET_I386)
740−#define ELFW_R_(type) ELF32_R_##type
741−#define ElfW_Rel ElfW(Rel)
742−
743734 #define REL_TYPE_DIRECT R_386_32
744735 #define R_XXX_THUNKFIX R_386_32
745736 #define R_XXX_RELATIVE R_386_RELATIVE
746737
747−#define ELFW_ST_BIND ELF32_ST_BIND
748−#define ELFW_ST_TYPE ELF32_ST_TYPE
749−#define ELFW_ST_INFO ELF32_ST_INFO
750738 #elif defined(TCC_TARGET_ARM)
751−#define ELFW_R_(type) ELF32_R_##type
752−#define ElfW_Rel ElfW(Rel)
753−
754739 #define REL_TYPE_DIRECT R_ARM_ABS32
755740 #define R_XXX_THUNKFIX R_ARM_ABS32
756741 #define R_XXX_RELATIVE R_ARM_RELATIVE
757742
758−#define ELFW_ST_BIND ELF32_ST_BIND
759−#define ELFW_ST_TYPE ELF32_ST_TYPE
760−#define ELFW_ST_INFO ELF32_ST_INFO
761743 #endif
762744 /*----------------------------------------------------------------------------*/
763745
@@ -1003,7 +985,7 @@ static void pe_build_reloc (struct pe_info *pe) · 239 unmodified lines
1003985
1004986 for(;;) {
1005987 if (rel < rel_end) {
1006− int type = ELFW_R_(TYPE)(rel->r_info);
988+ int type = ELFW(R_TYPE)(rel->r_info);
1007989 addr = rel->r_offset + s->sh_addr;
1008990 ++ rel;
1009991 if (type != REL_TYPE_DIRECT)
@@ -1185,8 +1167,8 @@ static void pe_relocate_rva (struct pe_info *pe, Section *s) · 175 unmodified lines
11851167 ElfW_Rel *rel, *rel_end;
11861168 rel_end = (ElfW_Rel *)(sr->data + sr->data_offset);
11871169 for(rel = (ElfW_Rel *)sr->data; rel < rel_end; rel++) {
1188− if (ELFW_R_(TYPE)(rel->r_info) == R_XXX_RELATIVE) {
1189− int sym_index = ELFW_R_(SYM)(rel->r_info);
1170+ if (ELFW(R_TYPE)(rel->r_info) == R_XXX_RELATIVE) {
1171+ int sym_index = ELFW(R_SYM)(rel->r_info);
11901172 DWORD addr = s->sh_addr;
11911173 if (sym_index) {
11921174 ElfW(Sym) *sym = (ElfW(Sym) *)symtab_section->data + sym_index;
@@ -1230,7 +1212,7 @@ static int pe_check_symbols(struct pe_info *pe) · 37 unmodified lines
12301212 if (sym->st_shndx == SHN_UNDEF) {
12311213
12321214 const char *name = symtab_section->link->data + sym->st_name;
1233− unsigned type = ELFW_ST_TYPE(sym->st_info);
1215+ unsigned type = ELFW(ST_TYPE)(sym->st_info);
12341216 int imp_sym = pe_find_import(pe->s1, sym);
12351217 struct import_symbol *is;
12361218
@@ -1274,7 +1256,7 @@ static int pe_check_symbols(struct pe_info *pe) · 37 unmodified lines
12741256 sprintf(buffer, "IAT.%s", name);
12751257 is->iat_index = put_elf_sym(
12761258 symtab_section, 0, sizeof(DWORD),
1277− ELFW_ST_INFO(STB_GLOBAL, STT_OBJECT),
1259+ ELFW(ST_INFO)(STB_GLOBAL, STT_OBJECT),
12781260 0, SHN_UNDEF, buffer);
12791261 #ifdef TCC_TARGET_ARM
12801262 put_elf_reloc(symtab_section, text_section,
@@ -1309,7 +1291,7 @@ static int pe_check_symbols(struct pe_info *pe) · 28 unmodified lines
13091291 ret = -1;
13101292
13111293 } else if (pe->s1->rdynamic
1312− && ELFW_ST_BIND(sym->st_info) != STB_LOCAL) {
1294+ && ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) {
13131295 /* if -rdynamic option, then export all non local symbols */
13141296 sym->st_other |= 1;
13151297 }
@@ -1408,8 +1390,8 @@ static void pe_print_section(FILE * f, Section * s) · 92 unmodified lines
14081390 (unsigned)sym->st_name,
14091391 (unsigned)sym->st_value,
14101392 (unsigned)sym->st_size,
1411− (unsigned)ELFW_ST_BIND(sym->st_info),
1412− (unsigned)ELFW_ST_TYPE(sym->st_info),
1393+ (unsigned)ELFW(ST_BIND)(sym->st_info),
1394+ (unsigned)ELFW(ST_TYPE)(sym->st_info),
14131395 (unsigned)sym->st_other,
14141396 (unsigned)sym->st_shndx,
14151397 name);
@@ -1417,12 +1399,12 @@ static void pe_print_section(FILE * f, Section * s) · 1 unmodified line
14171399 } else if (s->sh_type == SHT_RELX) {
14181400 ElfW_Rel *rel = (ElfW_Rel *) (p + i);
14191401 ElfW(Sym) *sym =
1420− (ElfW(Sym) *) s->link->data + ELFW_R_(SYM)(rel->r_info);
1402+ (ElfW(Sym) *) s->link->data + ELFW(R_SYM)(rel->r_info);
14211403 const char *name = s->link->link->data + sym->st_name;
14221404 fprintf(f, " %04X %02X %04X \"%s\"",
14231405 (unsigned)rel->r_offset,
1424− (unsigned)ELFW_R_(TYPE)(rel->r_info),
1425− (unsigned)ELFW_R_(SYM)(rel->r_info),
1406+ (unsigned)ELFW(R_TYPE)(rel->r_info),
1407+ (unsigned)ELFW(R_SYM)(rel->r_info),
14261408 name);
14271409 } else {
14281410 fprintf(f, " ");
@@ -1505,7 +1487,7 @@ ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, const voi · 76 unmodified lines
15051487 s1->dynsymtab_section,
15061488 (uplong)value,
15071489 dllindex, /* st_size */
1508− ELFW_ST_INFO(STB_GLOBAL, STT_NOTYPE),
1490+ ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE),
15091491 0,
15101492 value ? SHN_ABS : SHN_UNDEF,
15111493 name
@@ -1794,7 +1776,7 @@ static void pe_add_runtime_ex(TCCState *s1, struct pe_info *pe) · 282 unmodified lines
17941776 if (start_symbol)
17951777 add_elf_sym(symtab_section,
17961778 0, 0,
1797− ELFW_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0,
1779+ ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
17981780 SHN_UNDEF, start_symbol);
17991781
18001782 if (0 == s1->nostdlib) {
@@ -1820,7 +1802,7 @@ static void pe_add_runtime_ex(TCCState *s1, struct pe_info *pe) · 19 unmodified lines
18201802 /* for -run GUI's, put '_runwinmain' instead of 'main' */
18211803 add_elf_sym(symtab_section,
18221804 addr, 0,
1823− ELFW_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0,
1805+ ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
18241806 text_section->sh_num, "main");
18251807 }
18261808
win32/tools/tiny_libmaker.c+11−1
@@ -27,6 +27,16 @@ · 26 unmodified lines
2727
2828 #include "../../elf.h"
2929
30+#ifdef TCC_TARGET_X86_64
31+# define ELFCLASSW ELFCLASS64
32+# define ElfW(type) Elf##64##_##type
33+# define ELFW(type) ELF##64##_##type
34+#else
35+# define ELFCLASSW ELFCLASS32
36+# define ElfW(type) Elf##32##_##type
37+# define ELFW(type) ELF##32##_##type
38+#endif
39+
3040 #define ARMAG "!<arch>\n"
3141 #define ARFMAG "`\n"
3242
@@ -144,7 +154,7 @@ int main(int argc, char **argv) · 111 unmodified lines
144154 //printf("%s:\n", argv[iarg]);
145155 // elf header
146156 ehdr = (ElfW(Ehdr) *)buf;
147− if (ehdr->e_ident[4] != TCC_ELFCLASS)
157+ if (ehdr->e_ident[4] != ELFCLASSW)
148158 {
149159 fprintf(stderr, "Unsupported Elf Class: %s\n", argv[iarg]);
150160 fclose(fo);

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