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
270270 sr = s->reloc;
271271 if (!sr) {
272272 /* 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);
274274 /* if the symtab is allocated, then we consider the relocation
275275 are also */
276276 sr = new_section(tcc_state, buf, SHT_RELX, symtab->sh_flags);
@@ -724,12 +724,23 @@ static void build_got(TCCState *s1) · 447 unmodified lines
724724 s1->got->sh_entsize = 4;
725725 add_elf_sym(symtab_section, 0, 4, ELFW(ST_INFO)(STB_GLOBAL, STT_OBJECT),
726726 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
728729 /* keep space for _DYNAMIC pointer, if present */
729730 put32(ptr, 0);
730731 /* two dummy got entries */
731732 put32(ptr + 4, 0);
732733 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
733744 }
734745
735746 /* 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
775786 if (plt->data_offset == 0) {
776787 /* first plt entry */
777788 p = section_ptr_add(plt, 16);
778− p[0] = 0xff; /* pushl got + 4 */
789+ p[0] = 0xff; /* pushl got + PTR_SIZE */
779790 p[1] = modrm + 0x10;
780− put32(p + 2, 4);
781− p[6] = 0xff; /* jmp *(got + 8) */
791+ put32(p + 2, PTR_SIZE);
792+ p[6] = 0xff; /* jmp *(got + PTR_SIZE * 2) */
782793 p[7] = modrm;
783− put32(p + 8, 8);
794+ put32(p + 8, PTR_SIZE * 2);
784795 }
785796
786797 p = section_ptr_add(plt, 16);
@@ -840,7 +851,7 @@ static void put_got_entry(TCCState *s1, · 53 unmodified lines
840851 s1->got->data_offset,
841852 reloc_type, index);
842853 }
843− ptr = section_ptr_add(s1->got, sizeof(int));
854+ ptr = section_ptr_add(s1->got, PTR_SIZE);
844855 *ptr = 0;
845856 }
846857
@@ -1338,7 +1349,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 491 unmodified lines
13381349
13391350 /* add necessary space for other entries */
13401351 saved_dynamic_data_offset = dynamic->data_offset;
1341− dynamic->data_offset += 8 * 9;
1352+ dynamic->data_offset += sizeof(ElfW(Dyn)) * 9;
13421353 } else {
13431354 /* still need to build got entries in case of static link */
13441355 build_got_entries(s1);
@@ -1714,7 +1725,7 @@ int elf_output_file(TCCState *s1, const char *filename) · 369 unmodified lines
17141725 ehdr.e_ident[1] = ELFMAG1;
17151726 ehdr.e_ident[2] = ELFMAG2;
17161727 ehdr.e_ident[3] = ELFMAG3;
1717− ehdr.e_ident[4] = ELFCLASS32;
1728+ ehdr.e_ident[4] = TCC_ELFCLASS;
17181729 ehdr.e_ident[5] = ELFDATA2LSB;
17191730 ehdr.e_ident[6] = EV_CURRENT;
17201731 #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