Skip to content
11 changes: 5 additions & 6 deletions src/cmd/link/internal/ld/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -1828,7 +1828,7 @@ func (state *dodataState) allocateDataSectionForSym(seg *sym.Segment, s loader.S
sname = ".go." + sname[len("go:"):]
}
sect := addsection(ldr, state.ctxt.Arch, seg, sname, rwx)
sect.Align = symalign(ldr, s)
sect.Align = state.ctxt.Target.SectAlign(symalign(ldr, s))
state.datsize = Rnd(state.datsize, int64(sect.Align))
sect.Vaddr = uint64(state.datsize)
return sect
Expand All @@ -1853,6 +1853,7 @@ func (state *dodataState) allocateNamedDataSection(seg *sym.Segment, sName strin
}
}
}
sect.Align = state.ctxt.Target.SectAlign(sect.Align)
state.datsize = Rnd(state.datsize, int64(sect.Align))
sect.Vaddr = uint64(state.datsize)
return sect
Expand Down Expand Up @@ -1946,7 +1947,7 @@ func (state *dodataState) allocateDataSections(ctxt *Link) {
}
s := state.data[sym.SMODULEDATA][0]
sect := addsection(ldr, ctxt.Arch, &Segdata, ".go.module", 06)
sect.Align = symalign(ldr, s)
sect.Align = ctxt.Target.SectAlign(symalign(ldr, s))
state.datsize = Rnd(state.datsize, int64(sect.Align))
sect.Vaddr = uint64(state.datsize)
ldr.SetSymSect(s, sect)
Expand Down Expand Up @@ -2523,9 +2524,7 @@ func (ctxt *Link) textaddress() {
// Could parallelize, by assigning to text
// and then letting threads copy down, but probably not worth it.
sect := Segtext.Sections[0]

sect.Align = int32(Funcalign)

sect.Align = ctxt.Target.SectAlign(int32(Funcalign))
ldr := ctxt.loader

if *flagRandLayout != 0 {
Expand Down Expand Up @@ -2757,7 +2756,7 @@ func assignAddress(ctxt *Link, sect *sym.Section, n int, s loader.Sym, va uint64
sect = addsection(ctxt.loader, ctxt.Arch, &Segtext, ".text", 05)

sect.Vaddr = va
sect.Align = sectAlign
sect.Align = ctxt.Target.SectAlign(sectAlign)
ldr.SetSymSect(s, sect)

// Create a symbol for the start of the secondary text sections
Expand Down
8 changes: 6 additions & 2 deletions src/cmd/link/internal/ld/dwarf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2458,7 +2458,7 @@ func dwarfcompress(ctxt *Link) {
compressedSegName = ".zdebug_" + ldr.SymSect(s).Name[len(".debug_"):]
}
sect := addsection(ctxt.loader, ctxt.Arch, &Segdwarf, compressedSegName, 04)
sect.Align = int32(ctxt.Arch.Alignment)
sect.Align = ctxt.Target.SectAlign(int32(ctxt.Arch.Alignment))
sect.Length = uint64(len(z.compressed))
sect.Compressed = true
newSym := ldr.MakeSymbolBuilder(compressedSegName)
Expand Down Expand Up @@ -2488,7 +2488,11 @@ func dwarfcompress(ctxt *Link) {
sect := ldr.SymSect(s)
if sect != prevSect {
if ctxt.IsWindows() {
pos = uint64(Rnd(int64(pos), PEFILEALIGN))
align := int64(PEFILEALIGN)
if ctxt.LinkMode == LinkInternal {
align = PESECTALIGN
}
pos = uint64(Rnd(int64(pos), align))
}
sect.Vaddr = pos
prevSect = sect
Expand Down
5 changes: 5 additions & 0 deletions src/cmd/link/internal/ld/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,11 @@ func (ctxt *Link) loadlib() {
// We now have enough information to determine the link mode.
determineLinkMode(ctxt)

// Set minimum section alignment for PE files.
if ctxt.HeadType == objabi.Hwindows && ctxt.LinkMode == LinkInternal {
ctxt.Target.MinimumSectAlign = int32(PESECTALIGN)
}

if ctxt.LinkMode == LinkExternal && !iscgo && !(buildcfg.GOOS == "darwin" && ctxt.BuildMode != BuildModePlugin && ctxt.Arch.Family == sys.AMD64) {
// This indicates a user requested -linkmode=external.
// The startup code uses an import of runtime/cgo to decide
Expand Down
Loading