if targ.Type == sym.SDYNIMPORT {
ld.Errorf(s, "unexpected R_X86_64_PC32 relocation for dynamic symbol %s", targ.Name)
}
- if targ.Type == 0 || targ.Type == sym.SXREF {
+ // TODO(mwhudson): the test of VisibilityHidden here probably doesn't make
+ // sense and should be removed when someone has thought about it properly.
+ if (targ.Type == 0 || targ.Type == sym.SXREF) && !targ.Attr.VisibilityHidden() {
ld.Errorf(s, "unknown symbol %s in pcrel", targ.Name)
}
r.Type = objabi.R_PCREL
// (https://sourceware.org/bugzilla/show_bug.cgi?id=18270). So
// we convert the adrp; ld64 + R_ARM64_GOTPCREL into adrp;
// add + R_ADDRARM64.
- if !(r.Sym.Version != 0 || (r.Sym.Type&sym.SHIDDEN != 0) || r.Sym.Attr.Local()) && r.Sym.Type == sym.STEXT && ctxt.DynlinkingGo() {
+ if !(r.Sym.Version != 0 || r.Sym.Attr.VisibilityHidden() || r.Sym.Attr.Local()) && r.Sym.Type == sym.STEXT && ctxt.DynlinkingGo() {
if o2&0xffc00000 != 0xf9400000 {
ld.Errorf(s, "R_ARM64_GOTPCREL against unexpected instruction %x", o2)
}
continue
}
- if r.Sym != nil && (r.Sym.Type&(sym.SMASK|sym.SHIDDEN) == 0 || r.Sym.Type&sym.SMASK == sym.SXREF) {
+ if r.Sym != nil && ((r.Sym.Type == 0 && !r.Sym.Attr.VisibilityHidden()) || r.Sym.Type&sym.SMASK == sym.SXREF) {
// When putting the runtime but not main into a shared library
// these symbols are undefined and that's OK.
if ctxt.BuildMode == BuildModeShared {
if r.Sym == nil { // happens for some external ARM relocs
continue
}
- if r.Sym.Type == sym.Sxxx || r.Sym.Type == sym.SXREF {
+ // TODO(mwhudson): the test of VisibilityHidden here probably doesn't make
+ // sense and should be removed when someone has thought about it properly.
+ if (r.Sym.Type == sym.Sxxx || r.Sym.Type == sym.SXREF) && !r.Sym.Attr.VisibilityHidden() {
Errorf(s, "undefined: %q", r.Sym.Name)
}
if !r.Sym.Attr.Reachable() && r.Type != objabi.R_WEAKADDROFF {
}
}
class := IMAGE_SYM_CLASS_EXTERNAL
- if s.Version != 0 || (s.Type&sym.SHIDDEN != 0) || s.Attr.Local() {
+ if s.Version != 0 || s.Attr.VisibilityHidden() || s.Attr.Local() {
class = IMAGE_SYM_CLASS_STATIC
}
f.writeSymbol(ctxt.Out, s, value, sect, typ, uint8(class))
// maybe one day STB_WEAK.
bind := STB_GLOBAL
- if x.Version != 0 || (x.Type&sym.SHIDDEN != 0) || x.Attr.Local() {
+ if x.Version != 0 || x.Attr.VisibilityHidden() || x.Attr.Local() {
bind = STB_LOCAL
}
addr -= int64(xo.Sect.Vaddr)
}
other := STV_DEFAULT
- if x.Type&sym.SHIDDEN != 0 {
+ if x.Attr.VisibilityHidden() {
+ // TODO(mwhudson): We only set AttrVisibilityHidden in ldelf, i.e. when
+ // internally linking. But STV_HIDDEN visibility only matters in object
+ // files and shared libraries, and as we are a long way from implementing
+ // internal linking for shared libraries and only create object files when
+ // externally linking, I don't think this makes a lot of sense.
other = STV_HIDDEN
}
if ctxt.Arch.Family == sys.PPC64 && typ == STT_FUNC && x.Attr.Shared() && x.Name != "runtime.duffzero" && x.Name != "runtime.duffcopy" {
// set dupok generally. See http://codereview.appspot.com/5823055/
// comment #5 for details.
if s != nil && elfsym.other == 2 {
- s.Type |= sym.SHIDDEN
- s.Attr |= sym.AttrDuplicateOK
+ s.Attr |= sym.AttrDuplicateOK | sym.AttrVisibilityHidden
}
}
// so put it in the hash table.
if needSym != 0 {
s = syms.Lookup(elfsym.name, localSymVersion)
- s.Type |= sym.SHIDDEN
+ s.Attr |= sym.AttrVisibilityHidden
}
break
// don't bother to add them into the hash table
s = syms.Newsym(elfsym.name, localSymVersion)
- s.Type |= sym.SHIDDEN
+ s.Attr |= sym.AttrVisibilityHidden
}
case ElfSymBindWeak:
if needSym != 0 {
s = syms.Lookup(elfsym.name, 0)
if elfsym.other == 2 {
- s.Type |= sym.SHIDDEN
+ s.Attr |= sym.AttrVisibilityHidden
}
}
}
}
- if s != nil && s.Type == 0 && elfsym.type_ != ElfSymTypeSection {
+ // TODO(mwhudson): the test of VisibilityHidden here probably doesn't make
+ // sense and should be removed when someone has thought about it properly.
+ if s != nil && s.Type == 0 && !s.Attr.VisibilityHidden() && elfsym.type_ != ElfSymTypeSection {
s.Type = sym.SXREF
}
elfsym.sym = s
if targ.Type == sym.SDYNIMPORT {
ld.Errorf(s, "unexpected R_390_PCnn relocation for dynamic symbol %s", targ.Name)
}
- if targ.Type == 0 || targ.Type == sym.SXREF {
+ // TODO(mwhudson): the test of VisibilityHidden here probably doesn't make
+ // sense and should be removed when someone has thought about it properly.
+ if (targ.Type == 0 || targ.Type == sym.SXREF) && !targ.Attr.VisibilityHidden() {
ld.Errorf(s, "unknown symbol %s in pcrel", targ.Name)
}
r.Type = objabi.R_PCREL
AttrMakeTypelink
// AttrShared marks symbols compiled with the -shared option.
AttrShared
- // 14 attributes defined so far.
+ // AttrVisibilityHidden symbols are ELF symbols with
+ // visibility set to STV_HIDDEN. They become local symbols in
+ // the final executable. Only relevant when internally linking
+ // on an ELF platform.
+ AttrVisibilityHidden
+ // 15 attributes defined so far.
)
func (a Attribute) DuplicateOK() bool { return a&AttrDuplicateOK != 0 }
func (a Attribute) ReflectMethod() bool { return a&AttrReflectMethod != 0 }
func (a Attribute) MakeTypelink() bool { return a&AttrMakeTypelink != 0 }
func (a Attribute) Shared() bool { return a&AttrShared != 0 }
+func (a Attribute) VisibilityHidden() bool { return a&AttrVisibilityHidden != 0 }
func (a Attribute) CgoExport() bool {
return a.CgoExportDynamic() || a.CgoExportStatic()
SDWARFLOC
SSUB = SymKind(1 << 8)
SMASK = SymKind(SSUB - 1)
- SHIDDEN = SymKind(1 << 9)
SCONTAINER = SymKind(1 << 10) // has a sub-symbol
)
if targ.Type == sym.SDYNIMPORT {
ld.Errorf(s, "unexpected R_386_PC32 relocation for dynamic symbol %s", targ.Name)
}
- if targ.Type == 0 || targ.Type == sym.SXREF {
+ // TODO(mwhudson): the test of VisibilityHidden here probably doesn't make
+ // sense and should be removed when someone has thought about it properly.
+ if (targ.Type == 0 || targ.Type == sym.SXREF) && !targ.Attr.VisibilityHidden() {
ld.Errorf(s, "unknown symbol %s in pcrel", targ.Name)
}
r.Type = objabi.R_PCREL