}
func duintxx(s *obj.LSym, off int, v uint64, wid int) int {
- if s.Type == 0 {
- // TODO(josharian): Do this in obj.prepwrite instead.
- s.Type = objabi.SDATA
- }
if off&(wid-1) != 0 {
Fatalf("duintxxLSym: misaligned: v=%d wid=%d off=%d", v, wid, off)
}
if off < 0 || siz < 0 || off >= 1<<30 {
ctxt.Diag("prepwrite: bad off=%d siz=%d s=%v", off, siz, s)
}
- if s.Type == objabi.SBSS || s.Type == objabi.STLSBSS {
- ctxt.Diag("cannot supply data for BSS var")
+ switch s.Type {
+ case objabi.Sxxx, objabi.SBSS:
+ s.Type = objabi.SDATA
+ case objabi.SNOPTRBSS:
+ s.Type = objabi.SNOPTRDATA
+ case objabi.STLSBSS:
+ ctxt.Diag("cannot supply data for %v var %v", s.Type, s.Name)
}
l := off + int64(siz)
s.Grow(l)
}
}
for _, s := range ctxt.Data {
+ if len(s.P) > 0 {
+ switch s.Type {
+ case objabi.SBSS, objabi.SNOPTRBSS, objabi.STLSBSS:
+ ctxt.Diag("cannot provide data for %v sym %v", s.Type, s.Name)
+ }
+ }
w.wr.Write(s.P)
}
if flag&RODATA != 0 {
s.Type = objabi.SRODATA
} else if flag&NOPTR != 0 {
- s.Type = objabi.SNOPTRBSS
+ if s.Type == objabi.SDATA {
+ s.Type = objabi.SNOPTRDATA
+ } else {
+ s.Type = objabi.SNOPTRBSS
+ }
} else if flag&TLSBSS != 0 {
s.Type = objabi.STLSBSS
}
}
func dosymtype(ctxt *Link) {
- for _, s := range ctxt.Syms.Allsym {
- if len(s.P) > 0 {
- if s.Type == SBSS {
- s.Type = SDATA
- }
- if s.Type == SNOPTRBSS {
- s.Type = SNOPTRDATA
- }
- }
- // Create a new entry in the .init_array section that points to the
- // library initializer function.
- switch Buildmode {
- case BuildmodeCArchive, BuildmodeCShared:
- if s.Name == *flagEntrySymbol {
- addinitarrdata(ctxt, s)
+ switch Buildmode {
+ case BuildmodeCArchive, BuildmodeCShared:
+ for _, s := range ctxt.Syms.Allsym {
+ // Create a new entry in the .init_array section that points to the
+ // library initializer function.
+ switch Buildmode {
+ case BuildmodeCArchive, BuildmodeCShared:
+ if s.Name == *flagEntrySymbol {
+ addinitarrdata(ctxt, s)
+ }
}
}
}
case IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE: //.bss
s.Type = SNOPTRBSS
+ // It seems like this shouldn't happen, but it does, with symbol "runtime/cgo(.bss)".
+ // TODO: Figure out why and either document why it is ok or fix it at the source--
+ // either by eliminating the all-zero data or
+ // by making this SNOPTRDATA (IMAGE_SCN_CNT_INITIALIZED_DATA) to begin with.
+ if len(data) > 0 {
+ for _, x := range data {
+ if x != 0 {
+ Errorf(s, "non-zero data in .bss section: %q", data)
+ }
+ }
+ s.Type = SNOPTRDATA
+ }
case IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE: //.data
s.Type = SNOPTRDATA
continue
}
if len(s.P) > 0 {
- Errorf(s, "should not be bss (size=%d type=%d special=%v)", len(s.P), s.Type, s.Attr.Special())
+ Errorf(s, "should not be bss (size=%d type=%v special=%v)", len(s.P), s.Type, s.Attr.Special())
}
put(ctxt, s, s.Name, BSSSym, Symaddr(s), s.Gotype)
args = append(args, src)
out, err := exec.Command(testenv.GoToolPath(t), args...).CombinedOutput()
if err != nil {
- t.Fatalf("building test executable failed: %s %s", err, out)
+ t.Fatalf("building test executable for linktype %d failed: %s %s", linktype, err, out)
}
out, err = exec.Command(exe).CombinedOutput()
if err != nil {