OLD | NEW |
1 // Inferno utils/6l/asm.c | 1 // Inferno utils/6l/asm.c |
2 // http://code.google.com/p/inferno-os/source/browse/utils/6l/asm.c | 2 // http://code.google.com/p/inferno-os/source/browse/utils/6l/asm.c |
3 // | 3 // |
4 // Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. | 4 // Copyright © 1994-1999 Lucent Technologies Inc. All rights reserved. |
5 // Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net) | 5 // Portions Copyright © 1995-1997 C H Forsyth (forsyth@terzarima.net) |
6 // Portions Copyright © 1997-1999 Vita Nuova Limited | 6 // Portions Copyright © 1997-1999 Vita Nuova Limited |
7 // Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuov
a.com) | 7 // Portions Copyright © 2000-2007 Vita Nuova Holdings Limited (www.vitanuov
a.com) |
8 // Portions Copyright © 2004,2006 Bruce Ellis | 8 // Portions Copyright © 2004,2006 Bruce Ellis |
9 // Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net) | 9 // Portions Copyright © 2005-2007 C H Forsyth (forsyth@terzarima.net) |
10 // Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others | 10 // Revisions Copyright © 2000-2007 Lucent Technologies Inc. and others |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 ElfStrHash, | 247 ElfStrHash, |
248 ElfStrGot, | 248 ElfStrGot, |
249 ElfStrGotPlt, | 249 ElfStrGotPlt, |
250 ElfStrDynamic, | 250 ElfStrDynamic, |
251 ElfStrDynsym, | 251 ElfStrDynsym, |
252 ElfStrDynstr, | 252 ElfStrDynstr, |
253 ElfStrRela, | 253 ElfStrRela, |
254 ElfStrText, | 254 ElfStrText, |
255 ElfStrData, | 255 ElfStrData, |
256 ElfStrBss, | 256 ElfStrBss, |
| 257 ElfStrGosymcounts, |
257 ElfStrGosymtab, | 258 ElfStrGosymtab, |
258 ElfStrGopclntab, | 259 ElfStrGopclntab, |
259 ElfStrShstrtab, | 260 ElfStrShstrtab, |
260 ElfStrSymtab, | 261 ElfStrSymtab, |
261 ElfStrStrtab, | 262 ElfStrStrtab, |
262 NElfStr | 263 NElfStr |
263 }; | 264 }; |
264 | 265 |
265 vlong elfstr[NElfStr]; | 266 vlong elfstr[NElfStr]; |
266 | 267 |
(...skipping 22 matching lines...) Expand all Loading... |
289 if(HEADTYPE != 7 && HEADTYPE != 9) | 290 if(HEADTYPE != 7 && HEADTYPE != 9) |
290 return; | 291 return; |
291 | 292 |
292 /* predefine strings we need for section headers */ | 293 /* predefine strings we need for section headers */ |
293 shstrtab = lookup(".shstrtab", 0); | 294 shstrtab = lookup(".shstrtab", 0); |
294 elfstr[ElfStrEmpty] = addstring(shstrtab, ""); | 295 elfstr[ElfStrEmpty] = addstring(shstrtab, ""); |
295 elfstr[ElfStrText] = addstring(shstrtab, ".text"); | 296 elfstr[ElfStrText] = addstring(shstrtab, ".text"); |
296 elfstr[ElfStrData] = addstring(shstrtab, ".data"); | 297 elfstr[ElfStrData] = addstring(shstrtab, ".data"); |
297 elfstr[ElfStrBss] = addstring(shstrtab, ".bss"); | 298 elfstr[ElfStrBss] = addstring(shstrtab, ".bss"); |
298 if(!debug['s']) { | 299 if(!debug['s']) { |
| 300 elfstr[ElfStrGosymcounts] = addstring(shstrtab, ".gosymcounts"); |
299 elfstr[ElfStrGosymtab] = addstring(shstrtab, ".gosymtab"); | 301 elfstr[ElfStrGosymtab] = addstring(shstrtab, ".gosymtab"); |
300 elfstr[ElfStrGopclntab] = addstring(shstrtab, ".gopclntab"); | 302 elfstr[ElfStrGopclntab] = addstring(shstrtab, ".gopclntab"); |
301 if(debug['e']) { | 303 if(debug['e']) { |
302 elfstr[ElfStrSymtab] = addstring(shstrtab, ".symtab"); | 304 elfstr[ElfStrSymtab] = addstring(shstrtab, ".symtab"); |
303 elfstr[ElfStrStrtab] = addstring(shstrtab, ".strtab"); | 305 elfstr[ElfStrStrtab] = addstring(shstrtab, ".strtab"); |
304 } | 306 } |
305 } | 307 } |
306 elfstr[ElfStrShstrtab] = addstring(shstrtab, ".shstrtab"); | 308 elfstr[ElfStrShstrtab] = addstring(shstrtab, ".shstrtab"); |
307 | 309 |
308 if(!debug['d']) { /* -d suppresses dynamic loader format */ | 310 if(!debug['d']) { /* -d suppresses dynamic loader format */ |
309 elfstr[ElfStrInterp] = addstring(shstrtab, ".interp"); | 311 elfstr[ElfStrInterp] = addstring(shstrtab, ".interp"); |
310 elfstr[ElfStrHash] = addstring(shstrtab, ".hash"); | 312 elfstr[ElfStrHash] = addstring(shstrtab, ".hash"); |
311 elfstr[ElfStrGot] = addstring(shstrtab, ".got"); | 313 elfstr[ElfStrGot] = addstring(shstrtab, ".got"); |
312 elfstr[ElfStrGotPlt] = addstring(shstrtab, ".got.plt"); | 314 elfstr[ElfStrGotPlt] = addstring(shstrtab, ".got.plt"); |
313 elfstr[ElfStrDynamic] = addstring(shstrtab, ".dynamic"); | 315 elfstr[ElfStrDynamic] = addstring(shstrtab, ".dynamic"); |
314 elfstr[ElfStrDynsym] = addstring(shstrtab, ".dynsym"); | 316 elfstr[ElfStrDynsym] = addstring(shstrtab, ".dynsym"); |
315 elfstr[ElfStrDynstr] = addstring(shstrtab, ".dynstr"); | 317 elfstr[ElfStrDynstr] = addstring(shstrtab, ".dynstr"); |
316 elfstr[ElfStrRela] = addstring(shstrtab, ".rela"); | 318 elfstr[ElfStrRela] = addstring(shstrtab, ".rela"); |
317 | 319 |
318 /* dynamic symbol table - first entry all zeros */ | 320 /* dynamic symbol table - first entry all zeros */ |
319 s = lookup(".dynsym", 0); | 321 s = lookup(".dynsym", 0); |
320 » » s->type = SDATA; | 322 » » s->type = SELFDATA; |
321 s->reachable = 1; | 323 s->reachable = 1; |
322 s->value += ELF64SYMSIZE; | 324 s->value += ELF64SYMSIZE; |
323 | 325 |
324 /* dynamic string table */ | 326 /* dynamic string table */ |
325 s = lookup(".dynstr", 0); | 327 s = lookup(".dynstr", 0); |
| 328 s->type = SELFDATA; |
| 329 s->reachable = 1; |
| 330 s->value += ELF64SYMSIZE; |
326 addstring(s, ""); | 331 addstring(s, ""); |
327 dynstr = s; | 332 dynstr = s; |
328 | 333 |
329 /* relocation table */ | 334 /* relocation table */ |
330 s = lookup(".rela", 0); | 335 s = lookup(".rela", 0); |
331 s->reachable = 1; | 336 s->reachable = 1; |
332 » » s->type = SDATA; | 337 » » s->type = SELFDATA; |
333 | 338 |
334 /* global offset table */ | 339 /* global offset table */ |
335 s = lookup(".got", 0); | 340 s = lookup(".got", 0); |
336 s->reachable = 1; | 341 s->reachable = 1; |
337 » » s->type = SDATA; | 342 » » s->type = SELFDATA; |
338 | 343 |
339 /* got.plt - ??? */ | 344 /* got.plt - ??? */ |
340 s = lookup(".got.plt", 0); | 345 s = lookup(".got.plt", 0); |
341 s->reachable = 1; | 346 s->reachable = 1; |
342 » » s->type = SDATA; | 347 » » s->type = SELFDATA; |
| 348 » »······· |
| 349 » » /* hash */ |
| 350 » » s = lookup(".hash", 0); |
| 351 » » s->reachable = 1; |
| 352 » » s->type = SELFDATA; |
343 | 353 |
344 /* define dynamic elf table */ | 354 /* define dynamic elf table */ |
345 s = lookup(".dynamic", 0); | 355 s = lookup(".dynamic", 0); |
| 356 s->reachable = 1; |
| 357 s->type = SELFDATA; |
346 dynamic = s; | 358 dynamic = s; |
347 | 359 |
348 /* | 360 /* |
349 * relocation entries for dynimport symbols | 361 * relocation entries for dynimport symbols |
350 */ | 362 */ |
351 nsym = 1; // sym 0 is reserved | 363 nsym = 1; // sym 0 is reserved |
352 for(h=0; h<NHASH; h++) { | 364 for(h=0; h<NHASH; h++) { |
353 for(s=hash[h]; s!=S; s=s->link) { | 365 for(s=hash[h]; s!=S; s=s->link) { |
354 if(!s->reachable || (s->type != STEXT && s->type
!= SDATA && s->type != SBSS) || s->dynimpname == nil) | 366 if(!s->reachable || (s->type != STEXT && s->type
!= SDATA && s->type != SBSS) || s->dynimpname == nil) |
355 continue; | 367 continue; |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 ph->off = fo; | 742 ph->off = fo; |
731 ph->vaddr = va; | 743 ph->vaddr = va; |
732 ph->paddr = va; | 744 ph->paddr = va; |
733 ph->filesz = w; | 745 ph->filesz = w; |
734 ph->memsz = w+bsssize; | 746 ph->memsz = w+bsssize; |
735 ph->align = INITRND; | 747 ph->align = INITRND; |
736 | 748 |
737 if(!debug['s']) { | 749 if(!debug['s']) { |
738 ph = newElfPhdr(); | 750 ph = newElfPhdr(); |
739 ph->type = PT_LOAD; | 751 ph->type = PT_LOAD; |
740 » » » ph->flags = PF_W+PF_R; | 752 » » » ph->flags = PF_R; |
741 ph->off = symo; | 753 ph->off = symo; |
742 ph->vaddr = symdatva; | 754 ph->vaddr = symdatva; |
743 ph->paddr = symdatva; | 755 ph->paddr = symdatva; |
744 ph->filesz = 8+symsize+lcsize; | 756 ph->filesz = 8+symsize+lcsize; |
745 ph->memsz = 8+symsize+lcsize; | 757 ph->memsz = 8+symsize+lcsize; |
746 ph->align = INITRND; | 758 ph->align = INITRND; |
747 } | 759 } |
748 | 760 |
749 /* Dynamic linking sections */ | 761 /* Dynamic linking sections */ |
750 if (!debug['d']) { /* -d suppresses dynamic loader format *
/ | 762 if (!debug['d']) { /* -d suppresses dynamic loader format *
/ |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 sh->size = w; | 840 sh->size = w; |
829 sh->addralign = 8; | 841 sh->addralign = 8; |
830 | 842 |
831 fo = rnd(fo+w, INITRND); | 843 fo = rnd(fo+w, INITRND); |
832 va = rnd(va+w, INITRND); | 844 va = rnd(va+w, INITRND); |
833 w = datsize; | 845 w = datsize; |
834 | 846 |
835 sh = newElfShdr(elfstr[ElfStrData]); | 847 sh = newElfShdr(elfstr[ElfStrData]); |
836 sh->type = SHT_PROGBITS; | 848 sh->type = SHT_PROGBITS; |
837 sh->flags = SHF_WRITE+SHF_ALLOC; | 849 sh->flags = SHF_WRITE+SHF_ALLOC; |
838 » » sh->addr = va; | 850 » » sh->addr = va + elfdatsize; |
839 » » sh->off = fo; | 851 » » sh->off = fo + elfdatsize; |
840 » » sh->size = w; | 852 » » sh->size = w - elfdatsize; |
841 sh->addralign = 8; | 853 sh->addralign = 8; |
842 | 854 |
843 fo += w; | 855 fo += w; |
844 va += w; | 856 va += w; |
845 w = bsssize; | 857 w = bsssize; |
846 | 858 |
847 sh = newElfShdr(elfstr[ElfStrBss]); | 859 sh = newElfShdr(elfstr[ElfStrBss]); |
848 sh->type = SHT_NOBITS; | 860 sh->type = SHT_NOBITS; |
849 sh->flags = SHF_WRITE+SHF_ALLOC; | 861 sh->flags = SHF_WRITE+SHF_ALLOC; |
850 sh->addr = va; | 862 sh->addr = va; |
851 sh->off = fo; | 863 sh->off = fo; |
852 sh->size = w; | 864 sh->size = w; |
853 sh->addralign = 8; | 865 sh->addralign = 8; |
854 | 866 |
855 if (!debug['s']) { | 867 if (!debug['s']) { |
856 » » » fo = symo+8; | 868 » » » fo = symo; |
| 869 » » » w = 8; |
| 870 |
| 871 » » » sh = newElfShdr(elfstr[ElfStrGosymcounts]); |
| 872 » » » sh->type = SHT_PROGBITS; |
| 873 » » » sh->flags = SHF_ALLOC; |
| 874 » » » sh->off = fo; |
| 875 » » » sh->size = w; |
| 876 » » » sh->addralign = 1; |
| 877 » » » sh->addr = symdatva; |
| 878 |
| 879 » » » fo += w; |
857 w = symsize; | 880 w = symsize; |
858 | 881 |
859 sh = newElfShdr(elfstr[ElfStrGosymtab]); | 882 sh = newElfShdr(elfstr[ElfStrGosymtab]); |
860 sh->type = SHT_PROGBITS; | 883 sh->type = SHT_PROGBITS; |
| 884 sh->flags = SHF_ALLOC; |
861 sh->off = fo; | 885 sh->off = fo; |
862 sh->size = w; | 886 sh->size = w; |
863 sh->addralign = 1; | 887 sh->addralign = 1; |
| 888 sh->addr = symdatva + 8; |
864 | 889 |
865 fo += w; | 890 fo += w; |
866 w = lcsize; | 891 w = lcsize; |
867 | 892 |
868 sh = newElfShdr(elfstr[ElfStrGopclntab]); | 893 sh = newElfShdr(elfstr[ElfStrGopclntab]); |
869 sh->type = SHT_PROGBITS; | 894 sh->type = SHT_PROGBITS; |
| 895 sh->flags = SHF_ALLOC; |
870 sh->off = fo; | 896 sh->off = fo; |
871 sh->size = w; | 897 sh->size = w; |
872 sh->addralign = 1; | 898 sh->addralign = 1; |
| 899 sh->addr = symdatva + 8 + symsize; |
873 ························ | 900 ························ |
874 if(debug['e']) { | 901 if(debug['e']) { |
875 sh = newElfShdr(elfstr[ElfStrSymtab]); | 902 sh = newElfShdr(elfstr[ElfStrSymtab]); |
876 sh->type = SHT_SYMTAB; | 903 sh->type = SHT_SYMTAB; |
877 sh->off = elfsymo; | 904 sh->off = elfsymo; |
878 sh->size = elfsymsize; | 905 sh->size = elfsymsize; |
879 sh->addralign = 8; | 906 sh->addralign = 8; |
880 sh->entsize = 24; | 907 sh->entsize = 24; |
881 sh->link = eh->shnum; // link to strtab | 908 sh->link = eh->shnum; // link to strtab |
882 ························ | 909 ························ |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1095 curp = p; | 1122 curp = p; |
1096 if(!a->sym->reachable) | 1123 if(!a->sym->reachable) |
1097 diag("unreachable symbol in datblk - %s", a->sym->name); | 1124 diag("unreachable symbol in datblk - %s", a->sym->name); |
1098 if(a->sym->type == SMACHO) | 1125 if(a->sym->type == SMACHO) |
1099 continue; | 1126 continue; |
1100 | 1127 |
1101 if(p->as != AINIT && p->as != ADYNT) { | 1128 if(p->as != AINIT && p->as != ADYNT) { |
1102 for(j=l+(c-i)-1; j>=l; j--) | 1129 for(j=l+(c-i)-1; j>=l; j--) |
1103 if(buf.dbuf[j]) { | 1130 if(buf.dbuf[j]) { |
1104 print("%P\n", p); | 1131 print("%P\n", p); |
1105 » » » » » diag("multiple initialization"); | 1132 » » » » » diag("multiple initialization for %d %d"
, s, j); |
1106 break; | 1133 break; |
1107 } | 1134 } |
1108 } | 1135 } |
1109 | 1136 |
1110 switch(p->to.type) { | 1137 switch(p->to.type) { |
1111 case D_FCONST: | 1138 case D_FCONST: |
1112 switch(c) { | 1139 switch(c) { |
1113 default: | 1140 default: |
1114 case 4: | 1141 case 4: |
1115 fl = ieeedtof(&p->to.ieee); | 1142 fl = ieeedtof(&p->to.ieee); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1276 if(r <= 0) | 1303 if(r <= 0) |
1277 return v; | 1304 return v; |
1278 v += r - 1; | 1305 v += r - 1; |
1279 c = v % r; | 1306 c = v % r; |
1280 if(c < 0) | 1307 if(c < 0) |
1281 c += r; | 1308 c += r; |
1282 v -= c; | 1309 v -= c; |
1283 return v; | 1310 return v; |
1284 } | 1311 } |
1285 | 1312 |
OLD | NEW |