Skip to content

Commit 9f5cd43

Browse files
cmd/link: put moduledata in its own .go.module section
There is a test for this in CL 721480 later in this series. For #76038 Change-Id: Ib7ed1f0b0aed2d929ca0f135b54d6b62112cae30 Reviewed-on: https://go-review.googlesource.com/c/go/+/720660 TryBot-Bypass: David Chase <drchase@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: David Chase <drchase@google.com>
1 parent 43cfd78 commit 9f5cd43

File tree

6 files changed

+70
-49
lines changed

6 files changed

+70
-49
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,6 +1937,26 @@ func (state *dodataState) allocateDataSections(ctxt *Link) {
19371937
}
19381938
ldr := ctxt.loader
19391939

1940+
// SMODULEDATA needs to be writable, but the GC doesn't need to
1941+
// look at it. We don't use allocateSingleSymSections because
1942+
// the name of the section is not the name of the symbol.
1943+
if len(state.data[sym.SMODULEDATA]) > 0 {
1944+
if len(state.data[sym.SMODULEDATA]) != 1 {
1945+
Errorf("internal error: more than one SMODULEDATA symbol")
1946+
}
1947+
s := state.data[sym.SMODULEDATA][0]
1948+
sect := addsection(ldr, ctxt.Arch, &Segdata, ".go.module", 06)
1949+
sect.Align = symalign(ldr, s)
1950+
state.datsize = Rnd(state.datsize, int64(sect.Align))
1951+
sect.Vaddr = uint64(state.datsize)
1952+
ldr.SetSymSect(s, sect)
1953+
state.setSymType(s, sym.SDATA)
1954+
ldr.SetSymValue(s, int64(uint64(state.datsize)-sect.Vaddr))
1955+
state.datsize += ldr.SymSize(s)
1956+
sect.Length = uint64(state.datsize) - sect.Vaddr
1957+
state.checkdatsize(sym.SMODULEDATA)
1958+
}
1959+
19401960
// writable .got (note that for PIE binaries .got goes in relro)
19411961
if len(state.data[sym.SELFGOT]) > 0 {
19421962
state.allocateNamedSectionAndAssignSyms(&Segdata, ".got", sym.SELFGOT, sym.SDATA, 06)

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -923,9 +923,7 @@ func (ctxt *Link) linksetup() {
923923
mdsb = ctxt.loader.MakeSymbolUpdater(moduledata)
924924
ctxt.loader.SetAttrLocal(moduledata, true)
925925
}
926-
// In all cases way we mark the moduledata as noptrdata to hide it from
927-
// the GC.
928-
mdsb.SetType(sym.SNOPTRDATA)
926+
mdsb.SetType(sym.SMODULEDATA)
929927
ctxt.loader.SetAttrReachable(moduledata, true)
930928
ctxt.Moduledata = moduledata
931929

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ func Xcoffadddynrel(target *Target, ldr *loader.Loader, syms *ArchSyms, s loader
12541254
break
12551255
}
12561256
}
1257-
} else if t := ldr.SymType(s); t.IsDATA() || t.IsNOPTRDATA() || t == sym.SBUILDINFO || t == sym.SXCOFFTOC {
1257+
} else if t := ldr.SymType(s); t.IsDATA() || t.IsNOPTRDATA() || t == sym.SBUILDINFO || t == sym.SXCOFFTOC || t == sym.SMODULEDATA {
12581258
switch ldr.SymSect(targ).Seg {
12591259
default:
12601260
ldr.Errorf(s, "unknown segment for .loader relocation with symbol %s", ldr.SymName(targ))

src/cmd/link/internal/sym/symkind.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ const (
9999
SFIPSINFO // go:fipsinfo aka crypto/internal/fips140/check.Linkinfo (why is this writable)?
100100
SELFSECT // .got.plt, .plt, .dynamic where appropriate.
101101
SMACHO // Used only for .llvmasm?
102-
SMACHOGOT // Mach-O GOT.
103102
SWINDOWS // Windows dynamic symbols.
103+
SMODULEDATA // Linker generated moduledata struct.
104104
SELFGOT // Writable ELF GOT section.
105+
SMACHOGOT // Mach-O GOT.
105106
SNOPTRDATA // Data with no heap pointers.
106107
SNOPTRDATAFIPSSTART // Start of FIPS non-pointer writable data.
107108
SNOPTRDATAFIPS // FIPS non-pointer writable data.

src/cmd/link/internal/sym/symkind_string.go

Lines changed: 45 additions & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/link/internal/wasm/asm.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ func asmb(ctxt *ld.Link, ldr *loader.Loader) {
127127
ldr.SymSect(ldr.Lookup("runtime.rodata", 0)),
128128
ldr.SymSect(ldr.Lookup("runtime.typelink", 0)),
129129
ldr.SymSect(ldr.Lookup("runtime.itablink", 0)),
130+
ldr.SymSect(ldr.Lookup("runtime.firstmoduledata", 0)),
130131
ldr.SymSect(ldr.Lookup("runtime.pclntab", 0)),
131132
ldr.SymSect(ldr.Lookup("runtime.noptrdata", 0)),
132133
ldr.SymSect(ldr.Lookup("runtime.data", 0)),

0 commit comments

Comments
 (0)