~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/cmd/ld/ldelf.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2014-11-18 15:12:26 UTC
  • mfrom: (14.2.12 vivid-proposed)
  • Revision ID: package-import@ubuntu.com-20141118151226-zug7vn93mn3dtiz3
Tags: 2:1.3.2-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - Support co-installability with gccgo-go tool:
    - d/rules,golang-go.install: Rename bin/go -> bin/golang-go
    - d/golang-go.{postinst,prerm}: Install/remove /usr/bin/go using
      alternatives.
  - d/copyright: Amendments for full compiliance with copyright format.
  - d/control: Demote golang-go.tools to Suggests to support Ubuntu MIR.
  - dropped patches (now upstream):
    - d/p/issue27650045_40001_50001.diff
    - d/p/issue28050043_60001_70001.diff
    - d/p/issue54790044_100001_110001.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
258
258
        uint64  align;
259
259
        uint64  entsize;
260
260
        uchar   *base;
261
 
        Sym     *sym;
 
261
        LSym    *sym;
262
262
};
263
263
 
264
264
struct ElfObj
301
301
        uchar   type;
302
302
        uchar   other;
303
303
        uint16  shndx;
304
 
        Sym*    sym;
 
304
        LSym*   sym;
305
305
};
306
306
 
307
307
uchar ElfMagic[4] = { 0x7F, 'E', 'L', 'F' };
312
312
static int      reltype(char*, int, uchar*);
313
313
 
314
314
int
315
 
valuecmp(Sym *a, Sym *b)
 
315
valuecmp(LSym *a, LSym *b)
316
316
{
317
317
        if(a->value < b->value)
318
318
                return -1;
336
336
        ElfSym sym;
337
337
        Endian *e;
338
338
        Reloc *r, *rp;
339
 
        Sym *s;
340
 
        Sym **symbols;
 
339
        LSym *s;
 
340
        LSym **symbols;
341
341
 
342
342
        symbols = nil;
343
343
 
344
344
        if(debug['v'])
345
345
                Bprint(&bso, "%5.2f ldelf %s\n", cputime(), pn);
346
346
 
347
 
        version++;
 
347
        ctxt->version++;
348
348
        base = Boffset(f);
349
349
 
350
350
        if(Bread(f, hdrbuf, sizeof hdrbuf) != sizeof hdrbuf)
529
529
                        goto bad;
530
530
                
531
531
                name = smprint("%s(%s)", pkg, sect->name);
532
 
                s = lookup(name, version);
 
532
                s = linklookup(ctxt, name, ctxt->version);
533
533
                free(name);
534
534
                switch((int)sect->flags&(ElfSectFlagAlloc|ElfSectFlagWrite|ElfSectFlagExec)) {
535
535
                default:
601
601
                s->size = sym.size;
602
602
                s->outer = sect->sym;
603
603
                if(sect->sym->type == STEXT) {
604
 
                        Prog *p;
605
 
 
606
 
                        if(s->text != P) {
607
 
                                if(!s->dupok)
 
604
                        if(s->external && !s->dupok)
608
605
                                        diag("%s: duplicate definition of %s", pn, s->name);
609
 
                        } else {
610
 
                                // build a TEXT instruction with a unique pc
611
 
                                // just to make the rest of the linker happy.
612
 
                                p = prg();
613
 
                                p->as = ATEXT;
614
 
                                p->from.type = D_EXTERN;
615
 
                                p->from.sym = s;
616
 
                                p->textflag = 7;
617
 
                                p->to.type = D_CONST;
618
 
                                p->link = nil;
619
 
                                p->pc = pc++;
620
 
                                s->text = p;
621
 
                        }
 
606
                        s->external = 1;
622
607
                }
623
608
        }
624
609
        
629
614
                if(s == S)
630
615
                        continue;
631
616
                if(s->sub)
632
 
                        s->sub = listsort(s->sub, valuecmp, offsetof(Sym, sub));
 
617
                        s->sub = listsort(s->sub, valuecmp, offsetof(LSym, sub));
633
618
                if(s->type == STEXT) {
634
 
                        if(etextp)
635
 
                                etextp->next = s;
 
619
                        if(s->onlist)
 
620
                                sysfatal("symbol %s listed multiple times", s->name);
 
621
                        s->onlist = 1;
 
622
                        if(ctxt->etextp)
 
623
                                ctxt->etextp->next = s;
636
624
                        else
637
 
                                textp = s;
638
 
                        etextp = s;
 
625
                                ctxt->textp = s;
 
626
                        ctxt->etextp = s;
639
627
                        for(s = s->sub; s != S; s = s->sub) {
640
 
                                etextp->next = s;
641
 
                                etextp = s;
 
628
                                if(s->onlist)
 
629
                                        sysfatal("symbol %s listed multiple times", s->name);
 
630
                                s->onlist = 1;
 
631
                                ctxt->etextp->next = s;
 
632
                                ctxt->etextp = s;
642
633
                        }
643
634
                }
644
635
        }
712
703
                                else
713
704
                                        diag("invalid rela size %d", rp->siz);
714
705
                        }
 
706
                        if(rp->siz == 4)
 
707
                                rp->add = (int32)rp->add;
 
708
                        //print("rel %s %d %d %s %#llx\n", sect->sym->name, rp->type, rp->siz, rp->sym->name, rp->add);
715
709
                }
716
710
                qsort(r, n, sizeof r[0], rbyoff);       // just in case
717
711
                
761
755
static int
762
756
readsym(ElfObj *obj, int i, ElfSym *sym, int needSym)
763
757
{
764
 
        Sym *s;
 
758
        LSym *s;
765
759
 
766
760
        if(i >= obj->nsymtab || i < 0) {
767
761
                werrstr("invalid elf symbol index");
808
802
                switch(sym->bind) {
809
803
                case ElfSymBindGlobal:
810
804
                        if(needSym) {
811
 
                                s = lookup(sym->name, 0);
 
805
                                s = linklookup(ctxt, sym->name, 0);
812
806
                                // for global scoped hidden symbols we should insert it into
813
807
                                // symbol hash table, but mark them as hidden.
814
808
                                // __i686.get_pc_thunk.bx is allowed to be duplicated, to
828
822
                                        // local names and hidden visiblity global names are unique
829
823
                                        // and should only reference by its index, not name, so we
830
824
                                        // don't bother to add them into hash table
831
 
                                        s = newsym(sym->name, version);
 
825
                                        s = linknewsym(ctxt, sym->name, ctxt->version);
832
826
                                        s->type |= SHIDDEN;
833
827
                                }
834
828
                        break;
835
829
                case ElfSymBindWeak:
836
830
                        if(needSym) {
837
 
                                s = newsym(sym->name, 0);
 
831
                                s = linknewsym(ctxt, sym->name, 0);
838
832
                                if(sym->other == 2)
839
833
                                        s->type |= SHIDDEN;
840
834
                        }