LEFT | RIGHT |
(no file at all) | |
1 /* | 1 /* |
2 Derived from Plan 9 from User Space's src/libmach/elf.h, elf.c | 2 Derived from Plan 9 from User Space's src/libmach/elf.h, elf.c |
3 http://code.swtch.com/plan9port/src/tip/src/libmach/ | 3 http://code.swtch.com/plan9port/src/tip/src/libmach/ |
4 | 4 |
5 Copyright © 2004 Russ Cox. | 5 Copyright © 2004 Russ Cox. |
6 Portions Copyright © 2008-2010 Google Inc. | 6 Portions Copyright © 2008-2010 Google Inc. |
7 Portions Copyright © 2010 The Go Authors. | 7 Portions Copyright © 2010 The Go Authors. |
8 | 8 |
9 Permission is hereby granted, free of charge, to any person obtaining a copy | 9 Permission is hereby granted, free of charge, to any person obtaining a copy |
10 of this software and associated documentation files (the "Software"), to deal | 10 of this software and associated documentation files (the "Software"), to deal |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 uchar hdrbuf[64]; | 321 uchar hdrbuf[64]; |
322 uchar *p; | 322 uchar *p; |
323 ElfHdrBytes *hdr; | 323 ElfHdrBytes *hdr; |
324 ElfObj *obj; | 324 ElfObj *obj; |
325 ElfSect *sect, *rsect; | 325 ElfSect *sect, *rsect; |
326 ElfSym sym; | 326 ElfSym sym; |
327 Endian *e; | 327 Endian *e; |
328 Reloc *r, *rp; | 328 Reloc *r, *rp; |
329 Sym *s; | 329 Sym *s; |
330 | 330 |
| 331 USED(pkg); |
331 if(debug['v']) | 332 if(debug['v']) |
332 Bprint(&bso, "%5.2f ldelf %s\n", cputime(), pn); | 333 Bprint(&bso, "%5.2f ldelf %s\n", cputime(), pn); |
333 | 334 |
334 version++; | 335 version++; |
335 base = Boffset(f); | 336 base = Boffset(f); |
336 | 337 |
337 » if(Bread(f, &hdrbuf, sizeof hdrbuf) != sizeof hdrbuf) | 338 » if(Bread(f, hdrbuf, sizeof hdrbuf) != sizeof hdrbuf) |
338 goto bad; | 339 goto bad; |
339 » hdr = (ElfHdrBytes*)&hdrbuf; | 340 » hdr = (ElfHdrBytes*)hdrbuf; |
340 if(memcmp(hdr->ident, ElfMagic, 4) != 0) | 341 if(memcmp(hdr->ident, ElfMagic, 4) != 0) |
341 goto bad; | 342 goto bad; |
342 switch(hdr->ident[5]) { | 343 switch(hdr->ident[5]) { |
343 case ElfDataLsb: | 344 case ElfDataLsb: |
344 e = ≤ | 345 e = ≤ |
345 break; | 346 break; |
346 case ElfDataMsb: | 347 case ElfDataMsb: |
347 e = &be; | 348 e = &be; |
348 break; | 349 break; |
349 default: | 350 default: |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 for(i=0; i<obj->nsect; i++) { | 512 for(i=0; i<obj->nsect; i++) { |
512 sect = &obj->sect[i]; | 513 sect = &obj->sect[i]; |
513 if((sect->type != ElfSectProgbits && sect->type != ElfSectNobits
) || !(sect->flags&ElfSectFlagAlloc)) | 514 if((sect->type != ElfSectProgbits && sect->type != ElfSectNobits
) || !(sect->flags&ElfSectFlagAlloc)) |
514 continue; | 515 continue; |
515 if(sect->type != ElfSectNobits && map(obj, sect) < 0) | 516 if(sect->type != ElfSectNobits && map(obj, sect) < 0) |
516 goto bad; | 517 goto bad; |
517 ················ | 518 ················ |
518 name = smprint("%s(%s)", pn, sect->name); | 519 name = smprint("%s(%s)", pn, sect->name); |
519 s = lookup(name, version); | 520 s = lookup(name, version); |
520 free(name); | 521 free(name); |
521 » » switch(sect->flags&(ElfSectFlagAlloc|ElfSectFlagWrite|ElfSectFla
gExec)) { | 522 » » switch((int)sect->flags&(ElfSectFlagAlloc|ElfSectFlagWrite|ElfSe
ctFlagExec)) { |
522 default: | 523 default: |
523 werrstr("unexpected flags for ELF section %s", sect->nam
e); | 524 werrstr("unexpected flags for ELF section %s", sect->nam
e); |
524 goto bad; | 525 goto bad; |
525 case ElfSectFlagAlloc: | 526 case ElfSectFlagAlloc: |
526 s->type = SRODATA; | 527 s->type = SRODATA; |
527 break; | 528 break; |
528 case ElfSectFlagAlloc + ElfSectFlagWrite: | 529 case ElfSectFlagAlloc + ElfSectFlagWrite: |
529 s->type = SDATA; | 530 s->type = SDATA; |
530 break; | 531 break; |
531 case ElfSectFlagAlloc + ElfSectFlagExec: | 532 case ElfSectFlagAlloc + ElfSectFlagExec: |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
806 case R('8', R_386_GOTPC): | 807 case R('8', R_386_GOTPC): |
807 *siz = 4; | 808 *siz = 4; |
808 break; | 809 break; |
809 case R('6', R_X86_64_64): | 810 case R('6', R_X86_64_64): |
810 *siz = 8; | 811 *siz = 8; |
811 break; | 812 break; |
812 } | 813 } |
813 | 814 |
814 return 256+elftype; | 815 return 256+elftype; |
815 } | 816 } |
LEFT | RIGHT |