]> Cypherpunks repositories - gostls13.git/commitdiff
6l: OpenBSD support
authorJoel Sing <jsing@google.com>
Fri, 29 Jul 2011 17:47:41 +0000 (13:47 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 29 Jul 2011 17:47:41 +0000 (13:47 -0400)
Add linker support for OpenBSD ELF-64.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/4815066

src/cmd/6l/asm.c
src/cmd/6l/doc.go
src/cmd/6l/obj.c
src/cmd/6l/pass.c
src/cmd/ld/lib.h

index 39ee2db54f15546192f3cf38e6783198821757ed..f59a59efbe40e72f746fa05cb20fe110c6c43fe5 100644 (file)
@@ -43,6 +43,7 @@
 
 char linuxdynld[] = "/lib64/ld-linux-x86-64.so.2";
 char freebsddynld[] = "/libexec/ld-elf.so.1";
+char openbsddynld[] = "/usr/libexec/ld.so";
 
 char   zeroes[32];
 
@@ -554,7 +555,7 @@ doelf(void)
 {
        Sym *s, *shstrtab, *dynstr;
 
-       if(HEADTYPE != Hlinux && HEADTYPE != Hfreebsd)
+       if(HEADTYPE != Hlinux && HEADTYPE != Hfreebsd && HEADTYPE != Hopenbsd)
                return;
 
        /* predefine strings we need for section headers */
@@ -746,6 +747,7 @@ asmb(void)
                break;
        case Hlinux:
        case Hfreebsd:
+       case Hopenbsd:
                debug['8'] = 1; /* 64-bit addresses */
                /* index of elf text section; needed by asmelfsym, double-checked below */
                /* !debug['d'] causes extra sections before the .text section */
@@ -780,6 +782,7 @@ asmb(void)
                        break;
                case Hlinux:
                case Hfreebsd:
+               case Hopenbsd:
                        symo = rnd(HEADR+segtext.len, INITRND)+segdata.filelen;
                        symo = rnd(symo, INITRND);
                        break;
@@ -849,6 +852,7 @@ asmb(void)
                break;
        case Hlinux:
        case Hfreebsd:
+       case Hopenbsd:
                /* elf amd-64 */
 
                eh = getElfEhdr();
@@ -891,6 +895,9 @@ asmb(void)
                                case Hfreebsd:
                                        interpreter = freebsddynld;
                                        break;
+                               case Hopenbsd:
+                                       interpreter = openbsddynld;
+                                       break;
                                }
                        }
                        elfinterp(sh, startva, interpreter);
@@ -1053,7 +1060,9 @@ asmb(void)
                eh->ident[EI_MAG2] = 'L';
                eh->ident[EI_MAG3] = 'F';
                if(HEADTYPE == Hfreebsd)
-                       eh->ident[EI_OSABI] = 9;
+                       eh->ident[EI_OSABI] = ELFOSABI_FREEBSD;
+               else if(HEADTYPE == Hopenbsd)
+                       eh->ident[EI_OSABI] = ELFOSABI_OPENBSD;
                eh->ident[EI_CLASS] = ELFCLASS64;
                eh->ident[EI_DATA] = ELFDATA2LSB;
                eh->ident[EI_VERSION] = EV_CURRENT;
index cc7782cfeb0432c6f4254a0a551b1859a64e9d94..b8a6013d638890ed50828b54f023f80009cb38c6 100644 (file)
@@ -34,6 +34,8 @@ Options new in this version:
        Write Linux ELF binaries (default when $GOOS is linux)
 -Hfreebsd
        Write FreeBSD ELF binaries (default when $GOOS is freebsd)
+-Hopenbsd
+       Write OpenBSD ELF binaries (default when $GOOS is openbsd)
 -Hwindows
        Write Windows PE32+ binaries (default when $GOOS is windows)
 -I interpreter
index 306a3edf1ac4cfc9e0d2285c6c32a4c67435e045..a7ef58db471ca05358bee2500bb49af4c8725bed 100644 (file)
@@ -50,6 +50,7 @@ Header headers[] = {
    "darwin", Hdarwin,
    "linux", Hlinux,
    "freebsd", Hfreebsd,
+   "openbsd", Hopenbsd,
    "windows", Hwindows,
    "windowsgui", Hwindows,
    0, 0
@@ -62,6 +63,7 @@ Header headers[] = {
  *     -Hdarwin -Tx -Rx                is apple MH-exec
  *     -Hlinux -Tx -Rx                 is linux elf-exec
  *     -Hfreebsd -Tx -Rx               is FreeBSD elf-exec
+ *     -Hopenbsd -Tx -Rx               is OpenBSD elf-exec
  *     -Hwindows -Tx -Rx               is MS Windows PE32+
  *
  *     options used: 189BLQSWabcjlnpsvz
@@ -194,7 +196,8 @@ main(int argc, char *argv[])
                        INITDAT = 0;
                break;
        case Hlinux:    /* elf64 executable */
-       case Hfreebsd: /* freebsd */
+       case Hfreebsd:  /* freebsd */
+       case Hopenbsd:  /* openbsd */
                /*
                 * ELF uses TLS offset negative from FS.
                 * Translate 0(FS) and 8(FS) into -16(FS) and -8(FS).
index 773a30e4aba30ffb04c458859a97e751388f858b..d9e0b2fc1bf1b5ac37ebac0abf27921920691416 100644 (file)
@@ -294,7 +294,8 @@ patch(void)
                                p->from.offset = 0x58;
                        }
                }
-               if(HEADTYPE == Hlinux || HEADTYPE == Hfreebsd) {
+               if(HEADTYPE == Hlinux || HEADTYPE == Hfreebsd
+               || HEADTYPE == Hopenbsd) {
                        // ELF uses FS instead of GS.
                        if(p->from.type == D_INDIR+D_GS)
                                p->from.type = D_INDIR+D_FS;
@@ -419,7 +420,8 @@ dostkoff(void)
                if(!(p->from.scale & NOSPLIT)) {
                        p = appendp(p); // load g into CX
                        p->as = AMOVQ;
-                       if(HEADTYPE == Hlinux || HEADTYPE == Hfreebsd)  // ELF uses FS
+                       if(HEADTYPE == Hlinux || HEADTYPE == Hfreebsd
+                       || HEADTYPE == Hopenbsd)        // ELF uses FS
                                p->from.type = D_INDIR+D_FS;
                        else
                                p->from.type = D_INDIR+D_GS;
index 0764dc7a7931478ea38632526a09f23ba9c7e457..d13eea31ed8a9aae58c0b1f14309493e9cd9d511 100644 (file)
@@ -263,6 +263,7 @@ enum {
        Hlinux,         // Linux ELF
        Hfreebsd,       // FreeBSD ELF
        Hwindows,       // MS Windows PE
+       Hopenbsd,       // OpenBSD ELF
 };
 
 typedef struct Header Header;