add elf note section for OpenBSD. patches from jsing, applied to port by me.

This commit is contained in:
sthen 2012-09-19 21:10:38 +00:00
parent 129a168127
commit 8953ad4aeb
5 changed files with 269 additions and 1 deletions

View File

@ -1,10 +1,11 @@
# $OpenBSD: Makefile,v 1.5 2012/07/30 15:49:55 espie Exp $
# $OpenBSD: Makefile,v 1.6 2012/09/19 21:10:38 sthen Exp $
ONLY_FOR_ARCHS = amd64 i386
COMMENT = Go programming language
VERSION = 1.0.2
REVISION = 0
EXTRACT_SUFX = .src.tar.gz
DISTNAME = go${VERSION}
PKGNAME = go-${VERSION}

View File

@ -0,0 +1,63 @@
$OpenBSD: patch-src_cmd_6l_asm_c,v 1.1 2012/09/19 21:10:38 sthen Exp $
--- src/cmd/6l/asm.c.orig Thu Jun 14 04:23:38 2012
+++ src/cmd/6l/asm.c Mon Sep 17 11:38:32 2012
@@ -95,6 +95,7 @@ enum {
ElfStrGnuVersion,
ElfStrGnuVersionR,
ElfStrNoteNetbsdIdent,
+ ElfStrNoteOpenbsdIdent,
ElfStrNoPtrData,
ElfStrNoPtrBss,
NElfStr
@@ -577,6 +578,8 @@ doelf(void)
elfstr[ElfStrNoPtrBss] = addstring(shstrtab, ".noptrbss");
if(HEADTYPE == Hnetbsd)
elfstr[ElfStrNoteNetbsdIdent] = addstring(shstrtab, ".note.netbsd.ident");
+ if(HEADTYPE == Hopenbsd)
+ elfstr[ElfStrNoteOpenbsdIdent] = addstring(shstrtab, ".note.openbsd.ident");
addstring(shstrtab, ".elfdata");
addstring(shstrtab, ".rodata");
addstring(shstrtab, ".gosymtab");
@@ -781,7 +784,7 @@ asmb(void)
if(elfverneed)
elftextsh += 2;
}
- if(HEADTYPE == Hnetbsd)
+ if(HEADTYPE == Hnetbsd || HEADTYPE == Hopenbsd)
elftextsh += 1;
break;
case Hwindows:
@@ -939,12 +942,18 @@ asmb(void)
phsh(ph, sh);
}
- if(HEADTYPE == Hnetbsd) {
- sh = newElfShdr(elfstr[ElfStrNoteNetbsdIdent]);
- sh->type = SHT_NOTE;
- sh->flags = SHF_ALLOC;
- sh->addralign = 4;
- resoff -= elfnetbsdsig(sh, startva, resoff);
+ if(HEADTYPE == Hnetbsd || HEADTYPE == Hopenbsd) {
+ sh = nil;
+ switch(HEADTYPE) {
+ case Hnetbsd:
+ sh = newElfShdr(elfstr[ElfStrNoteNetbsdIdent]);
+ resoff -= elfnetbsdsig(sh, startva, resoff);
+ break;
+ case Hopenbsd:
+ sh = newElfShdr(elfstr[ElfStrNoteOpenbsdIdent]);
+ resoff -= elfopenbsdsig(sh, startva, resoff);
+ break;
+ }
ph = newElfPhdr();
ph->type = PT_NOTE;
@@ -1129,6 +1138,8 @@ asmb(void)
a += elfwriteinterp(elfstr[ElfStrInterp]);
if(HEADTYPE == Hnetbsd)
a += elfwritenetbsdsig(elfstr[ElfStrNoteNetbsdIdent]);
+ if(HEADTYPE == Hopenbsd)
+ a += elfwriteopenbsdsig(elfstr[ElfStrNoteOpenbsdIdent]);
if(a > ELFRESERVE)
diag("ELFRESERVE too small: %d > %d", a, ELFRESERVE);
break;

View File

@ -0,0 +1,63 @@
$OpenBSD: patch-src_cmd_8l_asm_c,v 1.1 2012/09/19 21:10:38 sthen Exp $
--- src/cmd/8l/asm.c.orig Thu Jun 14 04:23:38 2012
+++ src/cmd/8l/asm.c Mon Sep 17 11:38:32 2012
@@ -91,6 +91,7 @@ enum {
ElfStrGnuVersion,
ElfStrGnuVersionR,
ElfStrNoteNetbsdIdent,
+ ElfStrNoteOpenbsdIdent,
ElfStrNoPtrData,
ElfStrNoPtrBss,
NElfStr
@@ -534,6 +535,8 @@ doelf(void)
elfstr[ElfStrNoPtrBss] = addstring(shstrtab, ".noptrbss");
if(HEADTYPE == Hnetbsd)
elfstr[ElfStrNoteNetbsdIdent] = addstring(shstrtab, ".note.netbsd.ident");
+ if(HEADTYPE == Hopenbsd)
+ elfstr[ElfStrNoteOpenbsdIdent] = addstring(shstrtab, ".note.openbsd.ident");
addstring(shstrtab, ".elfdata");
addstring(shstrtab, ".rodata");
addstring(shstrtab, ".gosymtab");
@@ -721,7 +724,7 @@ asmb(void)
if(elfverneed)
elftextsh += 2;
}
- if(HEADTYPE == Hnetbsd)
+ if(HEADTYPE == Hnetbsd || HEADTYPE == Hopenbsd)
elftextsh += 1;
}
@@ -995,12 +998,18 @@ asmb(void)
phsh(ph, sh);
}
- if(HEADTYPE == Hnetbsd) {
- sh = newElfShdr(elfstr[ElfStrNoteNetbsdIdent]);
- sh->type = SHT_NOTE;
- sh->flags = SHF_ALLOC;
- sh->addralign = 4;
- resoff -= elfnetbsdsig(sh, startva, resoff);
+ if(HEADTYPE == Hnetbsd || HEADTYPE == Hopenbsd) {
+ sh = nil;
+ switch (HEADTYPE) {
+ case Hnetbsd:
+ sh = newElfShdr(elfstr[ElfStrNoteNetbsdIdent]);
+ resoff -= elfnetbsdsig(sh, startva, resoff);
+ break;
+ case Hopenbsd:
+ sh = newElfShdr(elfstr[ElfStrNoteOpenbsdIdent]);
+ resoff -= elfopenbsdsig(sh, startva, resoff);
+ break;
+ }
ph = newElfPhdr();
ph->type = PT_NOTE;
@@ -1195,6 +1204,8 @@ asmb(void)
a += elfwriteinterp(elfstr[ElfStrInterp]);
if(HEADTYPE == Hnetbsd)
a += elfwritenetbsdsig(elfstr[ElfStrNoteNetbsdIdent]);
+ if(HEADTYPE == Hopenbsd)
+ a += elfwriteopenbsdsig(elfstr[ElfStrNoteOpenbsdIdent]);
if(a > ELFRESERVE)
diag("ELFRESERVE too small: %d > %d", a, ELFRESERVE);
break;

View File

@ -0,0 +1,129 @@
$OpenBSD: patch-src_cmd_ld_elf_c,v 1.1 2012/09/19 21:10:38 sthen Exp $
--- src/cmd/ld/elf.c.orig Thu Jun 14 04:23:38 2012
+++ src/cmd/ld/elf.c Mon Sep 17 11:38:32 2012
@@ -348,20 +348,16 @@ elfwriteinterp(vlong stridx)
return sh->size;
}
-// Defined in NetBSD's sys/exec_elf.h
-#define ELF_NOTE_TYPE_NETBSD_TAG 1
-#define ELF_NOTE_NETBSD_NAMESZ 7
-#define ELF_NOTE_NETBSD_DESCSZ 4
-#define ELF_NOTE_NETBSD_NAME "NetBSD\0\0"
-#define ELF_NOTE_NETBSD_VERSION 599000000 /* NetBSD 5.99 */
-
int
-elfnetbsdsig(ElfShdr *sh, uint64 startva, uint64 resoff)
+elfnote(ElfShdr *sh, uint64 startva, uint64 resoff, int sz)
{
- int n;
+ uint64 n;
- n = sizeof(Elf_Note) + ELF_NOTE_NETBSD_NAMESZ + ELF_NOTE_NETBSD_DESCSZ + 1;
- n += resoff % 4;
+ n = sizeof(Elf_Note) + sz + resoff % 4;
+
+ sh->type = SHT_NOTE;
+ sh->flags = SHF_ALLOC;
+ sh->addralign = 4;
sh->addr = startva + resoff - n;
sh->off = resoff - n;
sh->size = n;
@@ -369,8 +365,9 @@ elfnetbsdsig(ElfShdr *sh, uint64 startva, uint64 resof
return n;
}
-int
-elfwritenetbsdsig(vlong stridx) {
+ElfShdr *
+elfwritenotehdr(vlong stridx, uint32 namesz, uint32 descsz, uint32 tag)
+{
ElfShdr *sh = nil;
int i;
@@ -378,15 +375,79 @@ elfwritenetbsdsig(vlong stridx) {
if(shdr[i]->name == stridx)
sh = shdr[i];
if(sh == nil)
- return 0;
+ return nil;
- // Write Elf_Note header followed by NetBSD string.
+ // Write Elf_Note header.
cseek(sh->off);
- LPUT(ELF_NOTE_NETBSD_NAMESZ);
- LPUT(ELF_NOTE_NETBSD_DESCSZ);
- LPUT(ELF_NOTE_TYPE_NETBSD_TAG);
- cwrite(ELF_NOTE_NETBSD_NAME, 8);
+ LPUT(namesz);
+ LPUT(descsz);
+ LPUT(tag);
+
+ return sh;
+}
+
+// NetBSD Signature (as per sys/exec_elf.h)
+#define ELF_NOTE_NETBSD_NAMESZ 7
+#define ELF_NOTE_NETBSD_DESCSZ 4
+#define ELF_NOTE_NETBSD_TAG 1
+#define ELF_NOTE_NETBSD_NAME "NetBSD\0\0"
+#define ELF_NOTE_NETBSD_VERSION 599000000 /* NetBSD 5.99 */
+
+int
+elfnetbsdsig(ElfShdr *sh, uint64 startva, uint64 resoff)
+{
+ int n;
+
+ n = ELF_NOTE_NETBSD_NAMESZ + ELF_NOTE_NETBSD_DESCSZ + 1;
+ return elfnote(sh, startva, resoff, n);
+}
+
+int
+elfwritenetbsdsig(vlong stridx)
+{
+ ElfShdr *sh;
+
+ // Write Elf_Note header.
+ sh = elfwritenotehdr(stridx, ELF_NOTE_NETBSD_NAMESZ, ELF_NOTE_NETBSD_DESCSZ, ELF_NOTE_NETBSD_TAG);
+ if(sh == nil)
+ return 0;
+
+ // Followed by NetBSD string and version.
+ cwrite(ELF_NOTE_NETBSD_NAME, ELF_NOTE_NETBSD_NAMESZ + 1);
LPUT(ELF_NOTE_NETBSD_VERSION);
+
+ return sh->size;
+}
+
+// OpenBSD Signature
+#define ELF_NOTE_OPENBSD_NAMESZ 8
+#define ELF_NOTE_OPENBSD_DESCSZ 4
+#define ELF_NOTE_OPENBSD_TAG 1
+#define ELF_NOTE_OPENBSD_NAME "OpenBSD\0"
+#define ELF_NOTE_OPENBSD_VERSION 0
+
+int
+elfopenbsdsig(ElfShdr *sh, uint64 startva, uint64 resoff)
+{
+ int n;
+
+ n = ELF_NOTE_OPENBSD_NAMESZ + ELF_NOTE_OPENBSD_DESCSZ;
+ return elfnote(sh, startva, resoff, n);
+}
+
+int
+elfwriteopenbsdsig(vlong stridx)
+{
+ ElfShdr *sh;
+
+ // Write Elf_Note header.
+ sh = elfwritenotehdr(stridx, ELF_NOTE_OPENBSD_NAMESZ, ELF_NOTE_OPENBSD_DESCSZ, ELF_NOTE_OPENBSD_TAG);
+ if(sh == nil)
+ return 0;
+
+ // Followed by OpenBSD string and version.
+ cwrite(ELF_NOTE_OPENBSD_NAME, ELF_NOTE_OPENBSD_NAMESZ);
+ LPUT(ELF_NOTE_OPENBSD_VERSION);
return sh->size;
}

View File

@ -0,0 +1,12 @@
$OpenBSD: patch-src_cmd_ld_elf_h,v 1.1 2012/09/19 21:10:38 sthen Exp $
--- src/cmd/ld/elf.h.orig Thu Jun 14 04:23:38 2012
+++ src/cmd/ld/elf.h Mon Sep 17 11:38:32 2012
@@ -972,6 +972,8 @@ int elfinterp(ElfShdr*, uint64, uint64, char*);
int elfwriteinterp(vlong);
int elfnetbsdsig(ElfShdr*, uint64, uint64);
int elfwritenetbsdsig(vlong);
+int elfopenbsdsig(ElfShdr*, uint64, uint64);
+int elfwriteopenbsdsig(vlong);
void elfdynhash(void);
ElfPhdr* elfphload(Segment*);
ElfShdr* elfshbits(Section*);