History

Better DLL support on x86-64.

- Add a macro TCC_OUTPUT_DLL_WITH_PLT. -- Now, the DLL with PLT support works only on x86-64, but we may be able to support it on all architectures eventually. - Define TCC_OUTPUT_DLL_WITH_PLT when target architecture is x86-64. - Current status (x86-64): -- Main program should be able to call functions in shared objects. -- Main program should be able to use global variables in shared objects. -- Shared objects should be able to call functions in main program. -- Shared objects can NOT use global variables in main program. - To fix the last issue, we may need to add support of -fPIC option in our code generator.

Shinichiro Hamaji committed 17 years ago

Commit 040ef001 parent fe8f2301 file · +39 −8Browse files

Unified · Split

tccelf.c+39−8
@@ -22,12 +22,17 @@ · 21 unmodified lines
2222 #define ElfW_Rel ElfW(Rela)
2323 #define SHT_RELX SHT_RELA
2424 #define REL_SECTION_FMT ".rela%s"
25+/* x86-64 requires PLT for DLLs */
26+#define TCC_OUTPUT_DLL_WITH_PLT
2527 #else
2628 #define ElfW_Rel ElfW(Rel)
2729 #define SHT_RELX SHT_REL
2830 #define REL_SECTION_FMT ".rel%s"
2931 #endif
3032
33+/* XXX: DLL with PLT would only work with x86-64 for now */
34+//#define TCC_OUTPUT_DLL_WITH_PLT
35+
3136 static int put_elf_str(Section *s, const char *sym)
3237 {
3338 int offset, len;
@@ -902,11 +907,15 @@ static void put_got_entry(TCCState *s1, · 868 unmodified lines
902907 uint8_t *p;
903908 int modrm;
904909
910+#if defined(TCC_OUTPUT_DLL_WITH_PLT)
911+ modrm = 0x25;
912+#else
905913 /* if we build a DLL, we add a %ebx offset */
906914 if (s1->output_type == TCC_OUTPUT_DLL)
907915 modrm = 0xa3;
908916 else
909917 modrm = 0x25;
918+#endif
910919
911920 /* add a PLT entry */
912921 plt = s1->plt;
@@ -932,7 +941,9 @@ static void put_got_entry(TCCState *s1, · 19 unmodified lines
932941
933942 /* the symbol is modified so that it will be relocated to
934943 the PLT */
944+#if !defined(TCC_OUTPUT_DLL_WITH_PLT)
935945 if (s1->output_type == TCC_OUTPUT_EXE)
946+#endif
936947 offset = plt->data_offset - 16;
937948 }
938949 #elif defined(TCC_TARGET_ARM)
@@ -1468,13 +1479,29 @@ int elf_output_file(TCCState *s1, const char *filename) · 529 unmodified lines
14681479 sym < sym_end;
14691480 sym++) {
14701481 if (ELFW(ST_BIND)(sym->st_info) != STB_LOCAL) {
1471− name = symtab_section->link->data + sym->st_name;
1472− index = put_elf_sym(s1->dynsym, sym->st_value, sym->st_size,
1473− sym->st_info, 0,
1474− sym->st_shndx, name);
1475− s1->symtab_to_dynsym[sym -
1476− (ElfW(Sym) *)symtab_section->data] =
1477− index;
1482+#if defined(TCC_OUTPUT_DLL_WITH_PLT)
1483+ if (ELFW(ST_TYPE)(sym->st_info) == STT_FUNC &&
1484+ sym->st_shndx == SHN_UNDEF) {
1485+ put_got_entry(s1, R_JMP_SLOT, sym->st_size,
1486+ sym->st_info,
1487+ sym - (ElfW(Sym) *)symtab_section->data);
1488+ }
1489+ else if (ELFW(ST_TYPE)(sym->st_info) == STT_OBJECT) {
1490+ put_got_entry(s1, R_X86_64_GLOB_DAT, sym->st_size,
1491+ sym->st_info,
1492+ sym - (ElfW(Sym) *)symtab_section->data);
1493+ }
1494+ else
1495+#endif
1496+ {
1497+ name = symtab_section->link->data + sym->st_name;
1498+ index = put_elf_sym(s1->dynsym, sym->st_value, sym->st_size,
1499+ sym->st_info, 0,
1500+ sym->st_shndx, name);
1501+ s1->symtab_to_dynsym[sym -
1502+ (ElfW(Sym) *)symtab_section->data] =
1503+ index;
1504+ }
14781505 }
14791506 }
14801507 }
@@ -1727,7 +1754,11 @@ int elf_output_file(TCCState *s1, const char *filename) · 246 unmodified lines
17271754 put32(s1->got->data, dynamic->sh_addr);
17281755
17291756 /* relocate the PLT */
1730− if (file_type == TCC_OUTPUT_EXE) {
1757+ if (file_type == TCC_OUTPUT_EXE
1758+#if defined(TCC_OUTPUT_DLL_WITH_PLT)
1759+ || file_type == TCC_OUTPUT_DLL
1760+#endif
1761+ ) {
17311762 uint8_t *p, *p_end;
17321763
17331764 p = s1->plt->data;

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