return int(sh.size)
}
+// The race detector can't handle ASLR (address space layout randomization).
+// ASLR is on by default for NetBSD, so we turn the ASLR off eplicitly
+// using a magic elf Note when building race binaries.
+
+func elfnetbsdpax(sh *ElfShdr, startva uint64, resoff uint64) int {
+ n := int(Rnd(4, 4) + Rnd(4, 4))
+ return elfnote(sh, startva, resoff, n)
+}
+
+func elfwritenetbsdpax(out *OutBuf) int {
+ sh := elfwritenotehdr(out, ".note.netbsd.pax", 4 /* length of PaX\x00 */, 4 /* length of flags */, 0x03 /* PaX type */)
+ if sh == nil {
+ return 0
+ }
+ out.Write([]byte("PaX\x00"))
+ out.Write32(0x20) // 0x20 = Force disable ASLR
+ return int(sh.size)
+}
+
// OpenBSD Signature
const (
ELF_NOTE_OPENBSD_NAMESZ = 8
}
if ctxt.IsNetbsd() {
shstrtab.Addstring(".note.netbsd.ident")
+ if *flagRace {
+ shstrtab.Addstring(".note.netbsd.pax")
+ }
}
if ctxt.IsOpenbsd() {
shstrtab.Addstring(".note.openbsd.ident")
var pph *ElfPhdr
var pnote *ElfPhdr
+ if *flagRace && ctxt.IsNetbsd() {
+ sh := elfshname(".note.netbsd.pax")
+ resoff -= int64(elfnetbsdpax(sh, uint64(startva), uint64(resoff)))
+ pnote = newElfPhdr()
+ pnote.type_ = PT_NOTE
+ pnote.flags = PF_R
+ phsh(pnote, sh)
+ }
if ctxt.LinkMode == LinkExternal {
/* skip program headers */
eh.phoff = 0
a += int64(elfwritegobuildid(ctxt.Out))
}
}
+ if *flagRace && ctxt.IsNetbsd() {
+ a += int64(elfwritenetbsdpax(ctxt.Out))
+ }
if a > elfreserve {
Errorf(nil, "ELFRESERVE too small: %d > %d with %d text sections", a, elfreserve, numtext)