@@ -18,69 +18,76 @@ static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
1818 const char * secstrings ;
1919 uint64_t syms [NSYMS ] = {};
2020
21- Elf_Phdr * pt = (Elf_Phdr * )(addr + hdr -> e_phoff );
21+ Elf_Phdr * pt = (Elf_Phdr * )(addr + GET ( hdr -> e_phoff ) );
2222
2323 /* Walk the segment table. */
24- for (i = 0 ; i < hdr -> e_phnum ; i ++ ) {
25- if (pt [i ].p_type == PT_LOAD ) {
24+ for (i = 0 ; i < GET ( hdr -> e_phnum ) ; i ++ ) {
25+ if (GET ( pt [i ].p_type ) == PT_LOAD ) {
2626 if (found_load )
2727 fail ("multiple PT_LOAD segs\n" );
2828
29- if (pt [i ].p_offset != 0 || pt [i ].p_vaddr != 0 )
29+ if (GET (pt [i ].p_offset ) != 0 ||
30+ GET (pt [i ].p_vaddr ) != 0 )
3031 fail ("PT_LOAD in wrong place\n" );
3132
32- if (pt [i ].p_memsz != pt [i ].p_filesz )
33+ if (GET ( pt [i ].p_memsz ) != GET ( pt [i ].p_filesz ) )
3334 fail ("cannot handle memsz != filesz\n" );
3435
35- load_size = pt [i ].p_memsz ;
36+ load_size = GET ( pt [i ].p_memsz ) ;
3637 found_load = 1 ;
37- } else if (pt [i ].p_type == PT_DYNAMIC ) {
38- dyn = addr + pt [i ].p_offset ;
39- dyn_end = addr + pt [i ].p_offset + pt [i ].p_memsz ;
38+ } else if (GET (pt [i ].p_type ) == PT_DYNAMIC ) {
39+ dyn = addr + GET (pt [i ].p_offset );
40+ dyn_end = addr + GET (pt [i ].p_offset ) +
41+ GET (pt [i ].p_memsz );
4042 }
4143 }
4244 if (!found_load )
4345 fail ("no PT_LOAD seg\n" );
4446 data_size = (load_size + 4095 ) / 4096 * 4096 ;
4547
4648 /* Walk the dynamic table */
47- for (i = 0 ; dyn + i < dyn_end && dyn [i ].d_tag != DT_NULL ; i ++ ) {
48- if (dyn [i ].d_tag == DT_REL || dyn [i ].d_tag == DT_RELSZ ||
49- dyn [i ].d_tag == DT_RELENT || dyn [i ].d_tag == DT_TEXTREL )
49+ for (i = 0 ; dyn + i < dyn_end && GET (dyn [i ].d_tag ) != DT_NULL ; i ++ ) {
50+ typeof (dyn [i ].d_tag ) tag = GET (dyn [i ].d_tag );
51+ if (tag == DT_REL || tag == DT_RELSZ ||
52+ tag == DT_RELENT || tag == DT_TEXTREL )
5053 fail ("vdso image contains dynamic relocations\n" );
5154 }
5255
5356 /* Walk the section table */
54- secstrings_hdr = addr + hdr -> e_shoff + hdr -> e_shentsize * hdr -> e_shstrndx ;
55- secstrings = addr + secstrings_hdr -> sh_offset ;
56- for (i = 0 ; i < hdr -> e_shnum ; i ++ ) {
57- Elf_Shdr * sh = addr + hdr -> e_shoff + hdr -> e_shentsize * i ;
58- if (sh -> sh_type == SHT_SYMTAB )
57+ secstrings_hdr = addr + GET (hdr -> e_shoff ) +
58+ GET (hdr -> e_shentsize )* GET (hdr -> e_shstrndx );
59+ secstrings = addr + GET (secstrings_hdr -> sh_offset );
60+ for (i = 0 ; i < GET (hdr -> e_shnum ); i ++ ) {
61+ Elf_Shdr * sh = addr + GET (hdr -> e_shoff ) +
62+ GET (hdr -> e_shentsize ) * i ;
63+ if (GET (sh -> sh_type ) == SHT_SYMTAB )
5964 symtab_hdr = sh ;
6065
61- if (!strcmp (secstrings + sh -> sh_name , ".altinstructions" ))
66+ if (!strcmp (secstrings + GET ( sh -> sh_name ) , ".altinstructions" ))
6267 alt_sec = sh ;
6368 }
6469
6570 if (!symtab_hdr )
6671 fail ("no symbol table\n" );
6772
68- strtab_hdr = addr + hdr -> e_shoff +
69- hdr -> e_shentsize * symtab_hdr -> sh_link ;
73+ strtab_hdr = addr + GET ( hdr -> e_shoff ) +
74+ GET ( hdr -> e_shentsize ) * GET ( symtab_hdr -> sh_link ) ;
7075
7176 /* Walk the symbol table */
72- for (i = 0 ; i < symtab_hdr -> sh_size / symtab_hdr -> sh_entsize ; i ++ ) {
77+ for (i = 0 ; i < GET (symtab_hdr -> sh_size ) / GET (symtab_hdr -> sh_entsize );
78+ i ++ ) {
7379 int k ;
74- Elf_Sym * sym = addr + symtab_hdr -> sh_offset +
75- symtab_hdr -> sh_entsize * i ;
76- const char * name = addr + strtab_hdr -> sh_offset + sym -> st_name ;
80+ Elf_Sym * sym = addr + GET (symtab_hdr -> sh_offset ) +
81+ GET (symtab_hdr -> sh_entsize ) * i ;
82+ const char * name = addr + GET (strtab_hdr -> sh_offset ) +
83+ GET (sym -> st_name );
7784 for (k = 0 ; k < NSYMS ; k ++ ) {
7885 if (!strcmp (name , required_syms [k ])) {
7986 if (syms [k ]) {
8087 fail ("duplicate symbol %s\n" ,
8188 required_syms [k ]);
8289 }
83- syms [k ] = sym -> st_value ;
90+ syms [k ] = GET ( sym -> st_value ) ;
8491 }
8592 }
8693 }
@@ -106,7 +113,7 @@ static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
106113 hdr -> e_shoff = 0 ;
107114 hdr -> e_shentsize = 0 ;
108115 hdr -> e_shnum = 0 ;
109- hdr -> e_shstrndx = SHN_UNDEF ;
116+ hdr -> e_shstrndx = htole16 ( SHN_UNDEF ) ;
110117
111118 if (!name ) {
112119 fwrite (addr , load_size , 1 , outfile );
@@ -140,9 +147,9 @@ static void GOFUNC(void *addr, size_t len, FILE *outfile, const char *name)
140147 fprintf (outfile , "\t},\n" );
141148 if (alt_sec ) {
142149 fprintf (outfile , "\t.alt = %lu,\n" ,
143- (unsigned long )alt_sec -> sh_offset );
150+ (unsigned long )GET ( alt_sec -> sh_offset ) );
144151 fprintf (outfile , "\t.alt_len = %lu,\n" ,
145- (unsigned long )alt_sec -> sh_size );
152+ (unsigned long )GET ( alt_sec -> sh_size ) );
146153 }
147154 for (i = 0 ; i < NSYMS ; i ++ ) {
148155 if (syms [i ])
0 commit comments