History

Make tccelf.c 64bit ready.

- Use REL_SECTION_FMT instead of ".rel%s". - Use PTR_SIZE instead of sizeof(int) for GOT entries. - Use sizeof(ElfW(Dyn)) instead of magic number 8. - Use TCC_ELFCLASS instead of ELFCLASS32.

Shinichiro Hamaji committed 17 years ago

Commit 27d23341 parent c92daa01 file · +20 −9Browse files

Unified · Split

tccelf.c+20−9
@@ -270,7 +270,7 @@ static void put_elf_reloc(Section *symtab, Section *s, unsigned long offset, · 269 unmodified lines
270 sr = s->reloc;270 sr = s->reloc;
271 if (!sr) {271 if (!sr) {
272 /* if no relocation section, create it */272 /* if no relocation section, create it */
273 snprintf(buf, sizeof(buf), ".rel%s", s->name);273 snprintf(buf, sizeof(buf), REL_SECTION_FMT, s->name);
274 /* if the symtab is allocated, then we consider the relocation274 /* if the symtab is allocated, then we consider the relocation
275 are also */275 are also */
276 sr = new_section(tcc_state, buf, SHT_RELX, symtab->sh_flags);276 sr = new_section(tcc_state, buf, SHT_RELX, symtab->sh_flags);
@@ -724,12 +724,23 @@ static void build_got(TCCState *s1) · 447 unmodified lines
724 s1->got->sh_entsize = 4;724 s1->got->sh_entsize = 4;
725 add_elf_sym(symtab_section, 0, 4, ELFW(ST_INFO)(STB_GLOBAL, STT_OBJECT), 725 add_elf_sym(symtab_section, 0, 4, ELFW(ST_INFO)(STB_GLOBAL, STT_OBJECT),
726 0, s1->got->sh_num, "_GLOBAL_OFFSET_TABLE_");726 0, s1->got->sh_num, "_GLOBAL_OFFSET_TABLE_");
727 ptr = section_ptr_add(s1->got, 3 * sizeof(int));727 ptr = section_ptr_add(s1->got, 3 * PTR_SIZE);
728#ifdef PTR_SIZE == 4
728 /* keep space for _DYNAMIC pointer, if present */729 /* keep space for _DYNAMIC pointer, if present */
729 put32(ptr, 0);730 put32(ptr, 0);
730 /* two dummy got entries */731 /* two dummy got entries */
731 put32(ptr + 4, 0);732 put32(ptr + 4, 0);
732 put32(ptr + 8, 0);733 put32(ptr + 8, 0);
734#else
735 /* keep space for _DYNAMIC pointer, if present */
736 put32(ptr, 0);
737 put32(ptr + 4, 0);
738 /* two dummy got entries */
739 put32(ptr + 8, 0);
740 put32(ptr + 12, 0);
741 put32(ptr + 16, 0);
742 put32(ptr + 20, 0);
743#endif
733}744}
734 745
735/* put a got entry corresponding to a symbol in symtab_section. 'size'746/* put a got entry corresponding to a symbol in symtab_section. 'size'
@@ -775,12 +786,12 @@ static void put_got_entry(TCCState *s1, · 39 unmodified lines
775 if (plt->data_offset == 0) {786 if (plt->data_offset == 0) {
776 /* first plt entry */787 /* first plt entry */
777 p = section_ptr_add(plt, 16);788 p = section_ptr_add(plt, 16);
778 p[0] = 0xff; /* pushl got + 4 */789 p[0] = 0xff; /* pushl got + PTR_SIZE */
779 p[1] = modrm + 0x10;790 p[1] = modrm + 0x10;
780 put32(p + 2, 4);791 put32(p + 2, PTR_SIZE);
781 p[6] = 0xff; /* jmp *(got + 8) */792 p[6] = 0xff; /* jmp *(got + PTR_SIZE * 2) */
782 p[7] = modrm;793 p[7] = modrm;
783 put32(p + 8, 8);794 put32(p + 8, PTR_SIZE * 2);
784 }795 }
785 796
786 p = section_ptr_add(plt, 16);797 p = section_ptr_add(plt, 16);
@@ -840,7 +851,7 @@ static void put_got_entry(TCCState *s1, · 53 unmodified lines
840 s1->got->data_offset, 851 s1->got->data_offset,
841 reloc_type, index);852 reloc_type, index);
842 }853 }
843 ptr = section_ptr_add(s1->got, sizeof(int));854 ptr = section_ptr_add(s1->got, PTR_SIZE);
844 *ptr = 0;855 *ptr = 0;
845}856}
846 857
@@ -1338,7 +1349,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 491 unmodified lines
1338 1349
1339 /* add necessary space for other entries */1350 /* add necessary space for other entries */
1340 saved_dynamic_data_offset = dynamic->data_offset;1351 saved_dynamic_data_offset = dynamic->data_offset;
1341 dynamic->data_offset += 8 * 9;1352 dynamic->data_offset += sizeof(ElfW(Dyn)) * 9;
1342 } else {1353 } else {
1343 /* still need to build got entries in case of static link */1354 /* still need to build got entries in case of static link */
1344 build_got_entries(s1);1355 build_got_entries(s1);
@@ -1714,7 +1725,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 369 unmodified lines
1714 ehdr.e_ident[1] = ELFMAG1;1725 ehdr.e_ident[1] = ELFMAG1;
1715 ehdr.e_ident[2] = ELFMAG2;1726 ehdr.e_ident[2] = ELFMAG2;
1716 ehdr.e_ident[3] = ELFMAG3;1727 ehdr.e_ident[3] = ELFMAG3;
1717 ehdr.e_ident[4] = ELFCLASS32;1728 ehdr.e_ident[4] = TCC_ELFCLASS;
1718 ehdr.e_ident[5] = ELFDATA2LSB;1729 ehdr.e_ident[5] = ELFDATA2LSB;
1719 ehdr.e_ident[6] = EV_CURRENT;1730 ehdr.e_ident[6] = EV_CURRENT;
1720#ifdef __FreeBSD__1731#ifdef __FreeBSD__

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