Skip to content

Commit 2ada216

Browse files
committed
add PVH ELF note on GOOS=tamago targets
1 parent 4c30482 commit 2ada216

File tree

1 file changed

+37
-0
lines changed
  • src/cmd/link/internal/ld

1 file changed

+37
-0
lines changed

src/cmd/link/internal/ld/elf.go

+37
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,31 @@ func elfwritegobuildid(out *OutBuf) int {
901901
return int(sh.Size)
902902
}
903903

904+
const (
905+
ELF_NOTE_PVH_TAG = 0x12
906+
)
907+
908+
var ELF_NOTE_PVH_NAME = []byte("Xen\x00")
909+
910+
func elfpvh(sh *ElfShdr, startva uint64, resoff uint64) int {
911+
n := len(ELF_NOTE_PVH_NAME) + 8
912+
return elfnote(sh, startva, resoff, n)
913+
}
914+
915+
func elfwritepvh(ctxt *Link) int {
916+
sh := elfwritenotehdr(ctxt.Out, ".note.go.pvh", uint32(len(ELF_NOTE_PVH_NAME)), 8, ELF_NOTE_PVH_TAG)
917+
if sh == nil {
918+
return 0
919+
}
920+
921+
ctxt.Out.Write(ELF_NOTE_PVH_NAME)
922+
var entry = make([]byte, 8)
923+
binary.LittleEndian.PutUint64(entry, uint64(Entryvalue(ctxt)))
924+
ctxt.Out.Write(entry)
925+
926+
return int(sh.Size)
927+
}
928+
904929
// Go specific notes
905930
const (
906931
ELF_NOTE_GOPKGLIST_TAG = 1
@@ -1467,6 +1492,9 @@ func (ctxt *Link) doelf() {
14671492
if *flagBuildid != "" {
14681493
shstrtabAddstring(".note.go.buildid")
14691494
}
1495+
if buildcfg.GOOS == "tamago" {
1496+
shstrtabAddstring(".note.go.pvh")
1497+
}
14701498
shstrtabAddstring(".elfdata")
14711499
shstrtabAddstring(".rodata")
14721500
// See the comment about data.rel.ro.FOO section names in data.go.
@@ -2015,6 +2043,12 @@ func asmbElf(ctxt *Link) {
20152043
phsh(getpnote(), sh)
20162044
}
20172045

2046+
if buildcfg.GOOS == "tamago" {
2047+
sh := elfshname(".note.go.pvh")
2048+
resoff -= int64(elfpvh(sh, uint64(startva), uint64(resoff)))
2049+
phsh(getpnote(), sh)
2050+
}
2051+
20182052
// Additions to the reserved area must be above this line.
20192053

20202054
elfphload(&Segtext)
@@ -2385,6 +2419,9 @@ elfobj:
23852419
if *flagBuildid != "" {
23862420
a += int64(elfwritegobuildid(ctxt.Out))
23872421
}
2422+
if buildcfg.GOOS == "tamago" {
2423+
a += int64(elfwritepvh(ctxt))
2424+
}
23882425
}
23892426
if *flagRace && ctxt.IsNetbsd() {
23902427
a += int64(elfwritenetbsdpax(ctxt.Out))

0 commit comments

Comments
 (0)