Commit e0c430d5 authored by Russ Cox's avatar Russ Cox

cmd/6l, cmd/8l: fix BSD builds

Before this CL, running

        cd misc/cgo/test
        go test -c
        readelf --dyn-syms test.test | grep cgoexp

turned up many UNDEF symbols corresponding to symbols actually
in the binary but marked only cgo_export_static. Only symbols
marked cgo_export_dynamic should be listed in this mode.
And if the symbol is going to be listed, it should be listed with its
actual address instead of UNDEF.

The Linux dynamic linker didn't care about the seemingly missing
symbols, but the BSD one did.

This CL eliminates the symbols from the dyn-syms table.

R=golang-dev
TBR=golang-dev
CC=golang-dev
https://golang.org/cl/7624043
parent 51338095
......@@ -131,7 +131,7 @@ adddynrel(Sym *s, Reloc *r)
// Handle relocations found in ELF object files.
case 256 + R_X86_64_PC32:
if(targ->dynimpname != nil && !(targ->cgoexport & CgoExportDynamic))
if(targ->dynimpname != nil && !targ->cgoexport)
diag("unexpected R_X86_64_PC32 relocation for dynamic symbol %s", targ->name);
if(targ->type == 0 || targ->type == SXREF)
diag("unknown symbol %s in pcrel", targ->name);
......@@ -142,7 +142,7 @@ adddynrel(Sym *s, Reloc *r)
case 256 + R_X86_64_PLT32:
r->type = D_PCREL;
r->add += 4;
if(targ->dynimpname != nil && !(targ->cgoexport & CgoExportDynamic)) {
if(targ->dynimpname != nil && !targ->cgoexport) {
addpltsym(targ);
r->sym = lookup(".plt", 0);
r->add += targ->plt;
......@@ -150,7 +150,7 @@ adddynrel(Sym *s, Reloc *r)
return;
case 256 + R_X86_64_GOTPCREL:
if(targ->dynimpname == nil || (targ->cgoexport & CgoExportDynamic)) {
if(targ->dynimpname == nil || targ->cgoexport) {
// have symbol
if(r->off >= 2 && s->p[r->off-2] == 0x8b) {
// turn MOVQ of GOT entry into LEAQ of symbol itself
......@@ -171,7 +171,7 @@ adddynrel(Sym *s, Reloc *r)
return;
case 256 + R_X86_64_64:
if(targ->dynimpname != nil && !(targ->cgoexport & CgoExportDynamic))
if(targ->dynimpname != nil && !targ->cgoexport)
diag("unexpected R_X86_64_64 relocation for dynamic symbol %s", targ->name);
r->type = D_ADDR;
return;
......@@ -182,12 +182,12 @@ adddynrel(Sym *s, Reloc *r)
case 512 + MACHO_X86_64_RELOC_BRANCH*2 + 0:
// TODO: What is the difference between all these?
r->type = D_ADDR;
if(targ->dynimpname != nil && !(targ->cgoexport & CgoExportDynamic))
if(targ->dynimpname != nil && !targ->cgoexport)
diag("unexpected reloc for dynamic symbol %s", targ->name);
return;
case 512 + MACHO_X86_64_RELOC_BRANCH*2 + 1:
if(targ->dynimpname != nil && !(targ->cgoexport & CgoExportDynamic)) {
if(targ->dynimpname != nil && !targ->cgoexport) {
addpltsym(targ);
r->sym = lookup(".plt", 0);
r->add = targ->plt;
......@@ -201,12 +201,12 @@ adddynrel(Sym *s, Reloc *r)
case 512 + MACHO_X86_64_RELOC_SIGNED_2*2 + 1:
case 512 + MACHO_X86_64_RELOC_SIGNED_4*2 + 1:
r->type = D_PCREL;
if(targ->dynimpname != nil && !(targ->cgoexport & CgoExportDynamic))
if(targ->dynimpname != nil && !targ->cgoexport)
diag("unexpected pc-relative reloc for dynamic symbol %s", targ->name);
return;
case 512 + MACHO_X86_64_RELOC_GOT_LOAD*2 + 1:
if(targ->dynimpname == nil || (targ->cgoexport & CgoExportDynamic)) {
if(targ->dynimpname == nil || targ->cgoexport) {
// have symbol
// turn MOVQ of GOT entry into LEAQ of symbol itself
if(r->off < 2 || s->p[r->off-2] != 0x8b) {
......@@ -219,7 +219,7 @@ adddynrel(Sym *s, Reloc *r)
}
// fall through
case 512 + MACHO_X86_64_RELOC_GOT*2 + 1:
if(targ->dynimpname == nil || (targ->cgoexport & CgoExportDynamic))
if(targ->dynimpname == nil || targ->cgoexport)
diag("unexpected GOT reloc for non-dynamic symbol %s", targ->name);
addgotsym(targ);
r->type = D_PCREL;
......@@ -229,7 +229,7 @@ adddynrel(Sym *s, Reloc *r)
}
// Handle references to ELF symbols from our own object files.
if(targ->dynimpname == nil || (targ->cgoexport & CgoExportDynamic))
if(targ->dynimpname == nil || targ->cgoexport)
return;
switch(r->type) {
......@@ -470,7 +470,7 @@ adddynsym(Sym *s)
adduint32(d, addstring(lookup(".dynstr", 0), name));
/* type */
t = STB_GLOBAL << 4;
if((s->cgoexport & CgoExportDynamic) && (s->type&SMASK) == STEXT)
if(s->cgoexport && (s->type&SMASK) == STEXT)
t |= STT_FUNC;
else
t |= STT_OBJECT;
......@@ -480,7 +480,7 @@ adddynsym(Sym *s)
adduint8(d, 0);
/* section where symbol is defined */
if(!(s->cgoexport & CgoExportDynamic) && s->dynimpname != nil)
if(!s->cgoexport && s->dynimpname != nil)
adduint16(d, SHN_UNDEF);
else {
switch(s->type) {
......
......@@ -128,7 +128,7 @@ adddynrel(Sym *s, Reloc *r)
// Handle relocations found in ELF object files.
case 256 + R_386_PC32:
if(targ->dynimpname != nil && !(targ->cgoexport & CgoExportDynamic))
if(targ->dynimpname != nil && !targ->cgoexport)
diag("unexpected R_386_PC32 relocation for dynamic symbol %s", targ->name);
if(targ->type == 0 || targ->type == SXREF)
diag("unknown symbol %s in pcrel", targ->name);
......@@ -139,7 +139,7 @@ adddynrel(Sym *s, Reloc *r)
case 256 + R_386_PLT32:
r->type = D_PCREL;
r->add += 4;
if(targ->dynimpname != nil && !(targ->cgoexport & CgoExportDynamic)) {
if(targ->dynimpname != nil && !targ->cgoexport) {
addpltsym(targ);
r->sym = lookup(".plt", 0);
r->add += targ->plt;
......@@ -147,7 +147,7 @@ adddynrel(Sym *s, Reloc *r)
return;
case 256 + R_386_GOT32:
if(targ->dynimpname == nil || (targ->cgoexport & CgoExportDynamic)) {
if(targ->dynimpname == nil || targ->cgoexport) {
// have symbol
// turn MOVL of GOT entry into LEAL of symbol itself
if(r->off < 2 || s->p[r->off-2] != 0x8b) {
......@@ -175,19 +175,19 @@ adddynrel(Sym *s, Reloc *r)
return;
case 256 + R_386_32:
if(targ->dynimpname != nil && !(targ->cgoexport & CgoExportDynamic))
if(targ->dynimpname != nil && !targ->cgoexport)
diag("unexpected R_386_32 relocation for dynamic symbol %s", targ->name);
r->type = D_ADDR;
return;
case 512 + MACHO_GENERIC_RELOC_VANILLA*2 + 0:
r->type = D_ADDR;
if(targ->dynimpname != nil && !(targ->cgoexport & CgoExportDynamic))
if(targ->dynimpname != nil && !targ->cgoexport)
diag("unexpected reloc for dynamic symbol %s", targ->name);
return;
case 512 + MACHO_GENERIC_RELOC_VANILLA*2 + 1:
if(targ->dynimpname != nil && !(targ->cgoexport & CgoExportDynamic)) {
if(targ->dynimpname != nil && !targ->cgoexport) {
addpltsym(targ);
r->sym = lookup(".plt", 0);
r->add = targ->plt;
......@@ -198,7 +198,7 @@ adddynrel(Sym *s, Reloc *r)
return;
case 512 + MACHO_FAKE_GOTPCREL:
if(targ->dynimpname == nil || (targ->cgoexport & CgoExportDynamic)) {
if(targ->dynimpname == nil || targ->cgoexport) {
// have symbol
// turn MOVL of GOT entry into LEAL of symbol itself
if(r->off < 2 || s->p[r->off-2] != 0x8b) {
......@@ -217,7 +217,7 @@ adddynrel(Sym *s, Reloc *r)
}
// Handle references to ELF symbols from our own object files.
if(targ->dynimpname == nil || (targ->cgoexport & CgoExportDynamic))
if(targ->dynimpname == nil || targ->cgoexport)
return;
switch(r->type) {
......@@ -461,7 +461,7 @@ adddynsym(Sym *s)
/* type */
t = STB_GLOBAL << 4;
if((s->cgoexport & CgoExportDynamic) && (s->type&SMASK) == STEXT)
if(s->cgoexport && (s->type&SMASK) == STEXT)
t |= STT_FUNC;
else
t |= STT_OBJECT;
......@@ -469,7 +469,7 @@ adddynsym(Sym *s)
adduint8(d, 0);
/* shndx */
if(!(s->cgoexport & CgoExportDynamic) && s->dynimpname != nil)
if(!s->cgoexport && s->dynimpname != nil)
adduint16(d, SHN_UNDEF);
else {
switch(s->type) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment