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
1712#define R_C60HI16 0x55 // high 16 bit MVKH embedded1712#define R_C60HI16 0x55 // high 16 bit MVKH embedded
1713#define R_C60LO16 0x54 // low 16 bit MVKL embedded1713#define R_C60LO16 0x54 // low 16 bit MVKL embedded
1714 1714
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
1725#endif /* elf.h */1715#endif /* elf.h */
tcc.h+18−0
@@ -1150,6 +1150,24 @@ ST_INLN void inp(void); · 1149 unmodified lines
1150ST_FUNC int handle_eob(void);1150ST_FUNC int handle_eob(void);
1151#endif1151#endif
1152 1152
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
1153/* ------------ xxx-gen.c ------------ */1171/* ------------ xxx-gen.c ------------ */
1154 1172
1155ST_FUNC void gsym_addr(int t, int a);1173ST_FUNC void gsym_addr(int t, int a);
tccelf.c+1−16
@@ -20,23 +20,8 @@ · 19 unmodified lines
20 20
21#include "tcc.h"21#include "tcc.h"
22 22
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
35static int new_undef_sym = 0; /* Is there a new undefined sym since last new_undef_sym() */23static int new_undef_sym = 0; /* Is there a new undefined sym since last new_undef_sym() */
36 24
37/* XXX: DLL with PLT would only work with x86-64 for now */
38//#define TCC_OUTPUT_DLL_WITH_PLT
39
40ST_FUNC int put_elf_str(Section *s, const char *sym)25ST_FUNC int put_elf_str(Section *s, const char *sym)
41{26{
42 int offset, len;27 int offset, len;
@@ -2119,7 +2104,7 @@ static int elf_output_file(TCCState *s1, const char *filename) · 2076 unmodified lines
2119 ehdr.e_ident[1] = ELFMAG1;2104 ehdr.e_ident[1] = ELFMAG1;
2120 ehdr.e_ident[2] = ELFMAG2;2105 ehdr.e_ident[2] = ELFMAG2;
2121 ehdr.e_ident[3] = ELFMAG3;2106 ehdr.e_ident[3] = ELFMAG3;
2122 ehdr.e_ident[4] = TCC_ELFCLASS;2107 ehdr.e_ident[4] = ELFCLASSW;
2123 ehdr.e_ident[5] = ELFDATA2LSB;2108 ehdr.e_ident[5] = ELFDATA2LSB;
2124 ehdr.e_ident[6] = EV_CURRENT;2109 ehdr.e_ident[6] = EV_CURRENT;
2125#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)2110#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
726/*----------------------------------------------------------------------------*/726/*----------------------------------------------------------------------------*/
727 727
728#if defined(TCC_TARGET_X86_64)728#if defined(TCC_TARGET_X86_64)
729#define ELFW_R_(type) ELF64_R_##type
730#define ElfW_Rel ElfW(Rela)
731
732#define REL_TYPE_DIRECT R_X86_64_64729#define REL_TYPE_DIRECT R_X86_64_64
733#define R_XXX_THUNKFIX R_X86_64_PC32730#define R_XXX_THUNKFIX R_X86_64_PC32
734#define R_XXX_RELATIVE R_X86_64_RELATIVE731#define R_XXX_RELATIVE R_X86_64_RELATIVE
735 732
736#define ELFW_ST_BIND ELF64_ST_BIND
737#define ELFW_ST_TYPE ELF64_ST_TYPE
738#define ELFW_ST_INFO ELF64_ST_INFO
739#elif defined(TCC_TARGET_I386)733#elif defined(TCC_TARGET_I386)
740#define ELFW_R_(type) ELF32_R_##type
741#define ElfW_Rel ElfW(Rel)
742
743#define REL_TYPE_DIRECT R_386_32734#define REL_TYPE_DIRECT R_386_32
744#define R_XXX_THUNKFIX R_386_32735#define R_XXX_THUNKFIX R_386_32
745#define R_XXX_RELATIVE R_386_RELATIVE736#define R_XXX_RELATIVE R_386_RELATIVE
746 737
747#define ELFW_ST_BIND ELF32_ST_BIND
748#define ELFW_ST_TYPE ELF32_ST_TYPE
749#define ELFW_ST_INFO ELF32_ST_INFO
750#elif defined(TCC_TARGET_ARM)738#elif defined(TCC_TARGET_ARM)
751#define ELFW_R_(type) ELF32_R_##type
752#define ElfW_Rel ElfW(Rel)
753
754#define REL_TYPE_DIRECT R_ARM_ABS32739#define REL_TYPE_DIRECT R_ARM_ABS32
755#define R_XXX_THUNKFIX R_ARM_ABS32740#define R_XXX_THUNKFIX R_ARM_ABS32
756#define R_XXX_RELATIVE R_ARM_RELATIVE741#define R_XXX_RELATIVE R_ARM_RELATIVE
757 742
758#define ELFW_ST_BIND ELF32_ST_BIND
759#define ELFW_ST_TYPE ELF32_ST_TYPE
760#define ELFW_ST_INFO ELF32_ST_INFO
761#endif743#endif
762/*----------------------------------------------------------------------------*/744/*----------------------------------------------------------------------------*/
763 745
@@ -1003,7 +985,7 @@ static void pe_build_reloc (struct pe_info *pe) · 239 unmodified lines
1003 985
1004 for(;;) {986 for(;;) {
1005 if (rel < rel_end) {987 if (rel < rel_end) {
1006 int type = ELFW_R_(TYPE)(rel->r_info);988 int type = ELFW(R_TYPE)(rel->r_info);
1007 addr = rel->r_offset + s->sh_addr;989 addr = rel->r_offset + s->sh_addr;
1008 ++ rel;990 ++ rel;
1009 if (type != REL_TYPE_DIRECT)991 if (type != REL_TYPE_DIRECT)
@@ -1185,8 +1167,8 @@ static void pe_relocate_rva (struct pe_info *pe, Section *s) · 175 unmodified lines
1185 ElfW_Rel *rel, *rel_end;1167 ElfW_Rel *rel, *rel_end;
1186 rel_end = (ElfW_Rel *)(sr->data + sr->data_offset);1168 rel_end = (ElfW_Rel *)(sr->data + sr->data_offset);
1187 for(rel = (ElfW_Rel *)sr->data; rel < rel_end; rel++) {1169 for(rel = (ElfW_Rel *)sr->data; rel < rel_end; rel++) {
1188 if (ELFW_R_(TYPE)(rel->r_info) == R_XXX_RELATIVE) {1170 if (ELFW(R_TYPE)(rel->r_info) == R_XXX_RELATIVE) {
1189 int sym_index = ELFW_R_(SYM)(rel->r_info);1171 int sym_index = ELFW(R_SYM)(rel->r_info);
1190 DWORD addr = s->sh_addr;1172 DWORD addr = s->sh_addr;
1191 if (sym_index) {1173 if (sym_index) {
1192 ElfW(Sym) *sym = (ElfW(Sym) *)symtab_section->data + sym_index;1174 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
1230 if (sym->st_shndx == SHN_UNDEF) {1212 if (sym->st_shndx == SHN_UNDEF) {
1231 1213
1232 const char *name = symtab_section->link->data + sym->st_name;1214 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);
1234 int imp_sym = pe_find_import(pe->s1, sym);1216 int imp_sym = pe_find_import(pe->s1, sym);
1235 struct import_symbol *is;1217 struct import_symbol *is;
1236 1218
@@ -1274,7 +1256,7 @@ static int pe_check_symbols(struct pe_info *pe) · 37 unmodified lines
1274 sprintf(buffer, "IAT.%s", name);1256 sprintf(buffer, "IAT.%s", name);
1275 is->iat_index = put_elf_sym(1257 is->iat_index = put_elf_sym(
1276 symtab_section, 0, sizeof(DWORD),1258 symtab_section, 0, sizeof(DWORD),
1277 ELFW_ST_INFO(STB_GLOBAL, STT_OBJECT),1259 ELFW(ST_INFO)(STB_GLOBAL, STT_OBJECT),
1278 0, SHN_UNDEF, buffer);1260 0, SHN_UNDEF, buffer);
1279#ifdef TCC_TARGET_ARM1261#ifdef TCC_TARGET_ARM
1280 put_elf_reloc(symtab_section, text_section,1262 put_elf_reloc(symtab_section, text_section,
@@ -1309,7 +1291,7 @@ static int pe_check_symbols(struct pe_info *pe) · 28 unmodified lines
1309 ret = -1;1291 ret = -1;
1310 1292
1311 } else if (pe->s1->rdynamic1293 } else if (pe->s1->rdynamic
1312 && ELFW_ST_BIND(sym->st_info) != STB_LOCAL) {1294 && ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) {
1313 /* if -rdynamic option, then export all non local symbols */1295 /* if -rdynamic option, then export all non local symbols */
1314 sym->st_other |= 1;1296 sym->st_other |= 1;
1315 }1297 }
@@ -1408,8 +1390,8 @@ static void pe_print_section(FILE * f, Section * s) · 92 unmodified lines
1408 (unsigned)sym->st_name,1390 (unsigned)sym->st_name,
1409 (unsigned)sym->st_value,1391 (unsigned)sym->st_value,
1410 (unsigned)sym->st_size,1392 (unsigned)sym->st_size,
1411 (unsigned)ELFW_ST_BIND(sym->st_info),1393 (unsigned)ELFW(ST_BIND)(sym->st_info),
1412 (unsigned)ELFW_ST_TYPE(sym->st_info),1394 (unsigned)ELFW(ST_TYPE)(sym->st_info),
1413 (unsigned)sym->st_other,1395 (unsigned)sym->st_other,
1414 (unsigned)sym->st_shndx,1396 (unsigned)sym->st_shndx,
1415 name);1397 name);
@@ -1417,12 +1399,12 @@ static void pe_print_section(FILE * f, Section * s) · 1 unmodified line
1417 } else if (s->sh_type == SHT_RELX) {1399 } else if (s->sh_type == SHT_RELX) {
1418 ElfW_Rel *rel = (ElfW_Rel *) (p + i);1400 ElfW_Rel *rel = (ElfW_Rel *) (p + i);
1419 ElfW(Sym) *sym =1401 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);
1421 const char *name = s->link->link->data + sym->st_name;1403 const char *name = s->link->link->data + sym->st_name;
1422 fprintf(f, " %04X %02X %04X \"%s\"",1404 fprintf(f, " %04X %02X %04X \"%s\"",
1423 (unsigned)rel->r_offset,1405 (unsigned)rel->r_offset,
1424 (unsigned)ELFW_R_(TYPE)(rel->r_info),1406 (unsigned)ELFW(R_TYPE)(rel->r_info),
1425 (unsigned)ELFW_R_(SYM)(rel->r_info),1407 (unsigned)ELFW(R_SYM)(rel->r_info),
1426 name);1408 name);
1427 } else {1409 } else {
1428 fprintf(f, " ");1410 fprintf(f, " ");
@@ -1505,7 +1487,7 @@ ST_FUNC int pe_putimport(TCCState *s1, int dllindex, const char *name, const voi · 76 unmodified lines
1505 s1->dynsymtab_section,1487 s1->dynsymtab_section,
1506 (uplong)value,1488 (uplong)value,
1507 dllindex, /* st_size */1489 dllindex, /* st_size */
1508 ELFW_ST_INFO(STB_GLOBAL, STT_NOTYPE),1490 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE),
1509 0,1491 0,
1510 value ? SHN_ABS : SHN_UNDEF,1492 value ? SHN_ABS : SHN_UNDEF,
1511 name1493 name
@@ -1794,7 +1776,7 @@ static void pe_add_runtime_ex(TCCState *s1, struct pe_info *pe) · 282 unmodified lines
1794 if (start_symbol)1776 if (start_symbol)
1795 add_elf_sym(symtab_section,1777 add_elf_sym(symtab_section,
1796 0, 0,1778 0, 0,
1797 ELFW_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0,1779 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
1798 SHN_UNDEF, start_symbol);1780 SHN_UNDEF, start_symbol);
1799 1781
1800 if (0 == s1->nostdlib) {1782 if (0 == s1->nostdlib) {
@@ -1820,7 +1802,7 @@ static void pe_add_runtime_ex(TCCState *s1, struct pe_info *pe) · 19 unmodified lines
1820 /* for -run GUI's, put '_runwinmain' instead of 'main' */1802 /* for -run GUI's, put '_runwinmain' instead of 'main' */
1821 add_elf_sym(symtab_section,1803 add_elf_sym(symtab_section,
1822 addr, 0,1804 addr, 0,
1823 ELFW_ST_INFO(STB_GLOBAL, STT_NOTYPE), 0,1805 ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0,
1824 text_section->sh_num, "main");1806 text_section->sh_num, "main");
1825 }1807 }
1826 1808
win32/tools/tiny_libmaker.c+11−1
@@ -27,6 +27,16 @@ · 26 unmodified lines
27 27
28#include "../../elf.h"28#include "../../elf.h"
29 29
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
30#define ARMAG "!<arch>\n"40#define ARMAG "!<arch>\n"
31#define ARFMAG "`\n"41#define ARFMAG "`\n"
32 42
@@ -144,7 +154,7 @@ int main(int argc, char **argv) · 111 unmodified lines
144 //printf("%s:\n", argv[iarg]);154 //printf("%s:\n", argv[iarg]);
145 // elf header155 // elf header
146 ehdr = (ElfW(Ehdr) *)buf;156 ehdr = (ElfW(Ehdr) *)buf;
147 if (ehdr->e_ident[4] != TCC_ELFCLASS)157 if (ehdr->e_ident[4] != ELFCLASSW)
148 {158 {
149 fprintf(stderr, "Unsupported Elf Class: %s\n", argv[iarg]);159 fprintf(stderr, "Unsupported Elf Class: %s\n", argv[iarg]);
150 fclose(fo);160 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