]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.power64] cmd/ld: update for power64
authorShenghou Ma <minux@golang.org>
Thu, 7 Aug 2014 22:36:42 +0000 (18:36 -0400)
committerShenghou Ma <minux@golang.org>
Thu, 7 Aug 2014 22:36:42 +0000 (18:36 -0400)
LGTM=rsc
R=rsc, iant
CC=golang-codereviews
https://golang.org/cl/121380043

src/cmd/ld/data.c
src/cmd/ld/doc.go
src/cmd/ld/dwarf.c
src/cmd/ld/elf.c
src/cmd/ld/ldelf.c
src/cmd/ld/lib.c
src/cmd/ld/lib.h
src/cmd/ld/macho.c
src/cmd/ld/symtab.c

index 96eadd479ad1244010e46489725ea30b17c9d6ec..702f559a888b0745e987782501ebcab95902121c 100644 (file)
@@ -441,11 +441,11 @@ blk(LSym *start, int32 addr, int32 size)
                        continue;
                if(sym->value >= eaddr)
                        break;
+               ctxt->cursym = sym;
                if(sym->value < addr) {
                        diag("phase error: addr=%#llx but sym=%#llx type=%d", (vlong)addr, (vlong)sym->value, sym->type);
                        errorexit();
                }
-               ctxt->cursym = sym;
                for(; addr < sym->value; addr++)
                        cput(0);
                p = sym->p;
@@ -459,6 +459,8 @@ blk(LSym *start, int32 addr, int32 size)
                        diag("phase error: addr=%#llx value+size=%#llx", (vlong)addr, (vlong)sym->value+sym->size);
                        errorexit();
                }
+               if(sym->value+sym->size >= eaddr)
+                       break;
        }
 
        for(; addr < eaddr; addr++)
index 8135bd549c3ec21a5080e6a59e0a9bd533434204..cea809715d0f0c075bcf4b6abcfc66c6d3cb00b3 100644 (file)
@@ -10,8 +10,8 @@ Ld is the portable code for a modified version of the Plan 9 linker.  The origin
 
        http://plan9.bell-labs.com/magic/man2html/1/8l
 
-It reads object files (.5, .6, or .8 files) and writes a binary named for the
-architecture (5.out, 6.out, 8.out) by default (if $GOOS is windows, a .exe suffix
+It reads object files (.5, .6, .8, .9 files) and writes a binary named for the
+architecture (5.out, 6.out, 8.out, 9.out) by default (if $GOOS is windows, a .exe suffix
 will be appended).
 
 Major changes include:
@@ -22,7 +22,7 @@ Original options are listed on the manual page linked above.
 
 Usage:
        go tool 6l [flags] mainObj
-Substitute 6l with 8l or 5l as appropriate.
+Substitute 6l with 5l, 8l or 9l as appropriate.
 
 Options new in this version:
 
index 3f93f58184669186425365077c13be5ff13cf8a6..702d4dfcbb04fd548f8d91237030dd92fc942d3f 100644 (file)
@@ -2179,7 +2179,7 @@ dwarfaddshstrings(LSym *shstrtab)
        elfstrdbg[ElfStrDebugStr]      = addstring(shstrtab, ".debug_str");
        elfstrdbg[ElfStrGDBScripts]    = addstring(shstrtab, ".debug_gdb_scripts");
        if(linkmode == LinkExternal) {
-               if(thechar == '6') {
+               if(thechar == '6' || thechar == '9') {
                        elfstrdbg[ElfStrRelDebugInfo] = addstring(shstrtab, ".rela.debug_info");
                        elfstrdbg[ElfStrRelDebugAranges] = addstring(shstrtab, ".rela.debug_aranges");
                        elfstrdbg[ElfStrRelDebugLine] = addstring(shstrtab, ".rela.debug_line");
@@ -2234,7 +2234,7 @@ dwarfaddelfrelocheader(int elfstr, ElfShdr *shdata, vlong off, vlong size)
        ElfShdr *sh;
 
        sh = newElfShdr(elfstrdbg[elfstr]);
-       if(thechar == '6') {
+       if(thechar == '6' || thechar == '9') {
                sh->type = SHT_RELA;
        } else {
                sh->type = SHT_REL;
index 3196961f35c2124ecb6fe162bdbc092632082e99..6ac6b6ee82ee12a944a336d65fce49cfe4276d84 100644 (file)
@@ -45,6 +45,7 @@ elfinit(void)
        switch(thechar) {
        // 64-bit architectures
        case '6':
+       case '9':
                elf64 = 1;
                hdr.phoff = ELF64HDRSIZE;       /* Must be be ELF64HDRSIZE: first PHdr must follow ELF header */
                hdr.shoff = ELF64HDRSIZE;       /* Will move as we add PHeaders */
@@ -678,7 +679,7 @@ elfdynhash(void)
                elfwritedynentsym(s, DT_VERSYM, linklookup(ctxt, ".gnu.version", 0));
        }
 
-       if(thechar == '6') {
+       if(thechar == '6' || thechar == '9') {
                sy = linklookup(ctxt, ".rela.plt", 0);
                if(sy->size > 0) {
                        elfwritedynent(s, DT_PLTREL, DT_RELA);
@@ -804,7 +805,7 @@ elfshreloc(Section *sect)
        if(strcmp(sect->name, ".shstrtab") == 0 || strcmp(sect->name, ".tbss") == 0)
                return nil;
 
-       if(thechar == '6') {
+       if(thechar == '6' || thechar == '9') {
                prefix = ".rela";
                typ = SHT_RELA;
        } else {
@@ -931,7 +932,7 @@ doelf(void)
                debug['s'] = 0;
                debug['d'] = 1;
 
-               if(thechar == '6') {
+               if(thechar == '6' || thechar == '9') {
                        addstring(shstrtab, ".rela.text");
                        addstring(shstrtab, ".rela.rodata");
                        addstring(shstrtab, ".rela.typelink");
@@ -954,7 +955,7 @@ doelf(void)
 
        if(flag_shared) {
                addstring(shstrtab, ".init_array");
-               if(thechar == '6')
+               if(thechar == '6' || thechar == '9')
                        addstring(shstrtab, ".rela.init_array");
                else
                        addstring(shstrtab, ".rel.init_array");
@@ -975,7 +976,7 @@ doelf(void)
                addstring(shstrtab, ".dynamic");
                addstring(shstrtab, ".dynsym");
                addstring(shstrtab, ".dynstr");
-               if(thechar == '6') {
+               if(thechar == '6' || thechar == '9') {
                        addstring(shstrtab, ".rela");
                        addstring(shstrtab, ".rela.plt");
                } else {
@@ -990,7 +991,7 @@ doelf(void)
                s = linklookup(ctxt, ".dynsym", 0);
                s->type = SELFROSECT;
                s->reachable = 1;
-               if(thechar == '6')
+               if(thechar == '6' || thechar == '9')
                        s->size += ELF64SYMSIZE;
                else
                        s->size += ELF32SYMSIZE;
@@ -1004,7 +1005,7 @@ doelf(void)
                dynstr = s;
 
                /* relocation table */
-               if(thechar == '6')
+               if(thechar == '6' || thechar == '9')
                        s = linklookup(ctxt, ".rela", 0);
                else
                        s = linklookup(ctxt, ".rel", 0);
@@ -1031,7 +1032,7 @@ doelf(void)
                
                elfsetupplt();
                
-               if(thechar == '6')
+               if(thechar == '6' || thechar == '9')
                        s = linklookup(ctxt, ".rela.plt", 0);
                else
                        s = linklookup(ctxt, ".rel.plt", 0);
@@ -1056,13 +1057,13 @@ doelf(void)
                 */
                elfwritedynentsym(s, DT_HASH, linklookup(ctxt, ".hash", 0));
                elfwritedynentsym(s, DT_SYMTAB, linklookup(ctxt, ".dynsym", 0));
-               if(thechar == '6')
+               if(thechar == '6' || thechar == '9')
                        elfwritedynent(s, DT_SYMENT, ELF64SYMSIZE);
                else
                        elfwritedynent(s, DT_SYMENT, ELF32SYMSIZE);
                elfwritedynentsym(s, DT_STRTAB, linklookup(ctxt, ".dynstr", 0));
                elfwritedynentsymsize(s, DT_STRSZ, linklookup(ctxt, ".dynstr", 0));
-               if(thechar == '6') {
+               if(thechar == '6' || thechar == '9') {
                        elfwritedynentsym(s, DT_RELA, linklookup(ctxt, ".rela", 0));
                        elfwritedynentsymsize(s, DT_RELASZ, linklookup(ctxt, ".rela", 0));
                        elfwritedynent(s, DT_RELAENT, ELF64RELASIZE);
@@ -1148,6 +1149,9 @@ asmbelf(vlong symo)
        case '8':
                eh->machine = EM_386;
                break;
+       case '9':
+               eh->machine = EM_PPC64;
+               break;
        }
 
        startva = INITTEXT - HEADR;
@@ -1488,7 +1492,10 @@ elfobj:
                eh->ident[EI_CLASS] = ELFCLASS64;
        else
                eh->ident[EI_CLASS] = ELFCLASS32;
-       eh->ident[EI_DATA] = ELFDATA2LSB;
+       if(ctxt->arch->endian == BigEndian)
+               eh->ident[EI_DATA] = ELFDATA2MSB;
+       else
+               eh->ident[EI_DATA] = ELFDATA2LSB;
        eh->ident[EI_VERSION] = EV_CURRENT;
 
        if(linkmode == LinkExternal)
index 38e414755604a8aaffa6811f9e9ced457ee2c6af..284f7b21d6f37ed4a1b441dddca0b5ed8cf07ef4 100644 (file)
@@ -436,6 +436,12 @@ ldelf(Biobuf *f, char *pkg, int64 len, char *pn)
                        return;
                }
                break;
+       case '9':
+               if(obj->machine != ElfMachPower64 || hdr->ident[4] != ElfClass64) {
+                       diag("%s: elf object but not power64", pn);
+                       return;
+               }
+               break;
        }
 
        // load section list into memory.
index 0a5d8d99f2da4685d3e09d4015b91473f7143a2d..bdba217478b30a50c0046e5f7536b121c3b28871 100644 (file)
@@ -586,6 +586,7 @@ hostlink(void)
                argv[argc++] = "-m32";
                break;
        case '6':
+       case '9':
                argv[argc++] = "-m64";
                break;
        case '5':
@@ -1146,6 +1147,7 @@ stkcheck(Chain *up, int depth)
                        switch(r->type) {
                        case R_CALL:
                        case R_CALLARM:
+                       case R_CALLPOWER:
                                // Direct call.
                                ch.limit = limit - pcsp.value - callsize();
                                ch.sym = r->sym;
@@ -1525,7 +1527,7 @@ callgraph(void)
                        r = &s->r[i];
                        if(r->sym == nil)
                                continue;
-                       if((r->type == R_CALL || r->type == R_CALLARM) && r->sym->type == STEXT)
+                       if((r->type == R_CALL || r->type == R_CALLARM || r->type == R_CALLPOWER) && r->sym->type == STEXT)
                                Bprint(&bso, "%s calls %s\n", s->name, r->sym->name);
                }
        }
index 4094dfa6b1f849f873320d5d896661587ff8ed59..6ce880ea9ef30430e13be82bbc5c80a237821434 100644 (file)
 // A section further describes the pieces of that block for
 // use in debuggers and such.
 
-enum {
-       MAXIO           = 8192,
-};
-
 typedef struct Segment Segment;
 typedef struct Section Section;
 
index 61306bb7ca71989cf1993f946935bc22c0a63b5e..c645e64097643889e5c24b113053eb16f5d2fb15 100644 (file)
@@ -44,6 +44,7 @@ machoinit(void)
        switch(thechar) {
        // 64-bit architectures
        case '6':
+       case '9':
                macho64 = 1;
                break;
 
index 1805f97d3a31872c42892ecd9bd9f56c9774c835..8149a6716749aa5325789efbbf9a2e1ec8c57804 100644 (file)
@@ -78,6 +78,7 @@ putelfsyment(int off, vlong addr, vlong size, int info, int shndx, int other)
 {
        switch(thechar) {
        case '6':
+       case '9':
                LPUT(off);
                cput(info);
                cput(other);