// Handle relocations found in ELF object files.
case 256 + R_ARM_PLT32:
r->type = D_CALL;
- if(targ->dynimpname != nil && !(targ->cgoexport & CgoExportDynamic)) {
+ if(targ->type == SDYNIMPORT) {
addpltsym(targ);
r->sym = lookup(".plt", 0);
r->add = braddoff(r->add, targ->plt / 4);
return;
case 256 + R_ARM_GOT32: // R_ARM_GOT_BREL
- if(targ->dynimpname == nil || (targ->cgoexport & CgoExportDynamic)) {
+ if(targ->type != SDYNIMPORT) {
addgotsyminternal(targ);
} else {
addgotsym(targ);
return;
case 256 + R_ARM_GOT_PREL: // GOT(S) + A - P
- if(targ->dynimpname == nil || (targ->cgoexport & CgoExportDynamic)) {
+ if(targ->type != SDYNIMPORT) {
addgotsyminternal(targ);
} else {
addgotsym(targ);
case 256 + R_ARM_CALL:
r->type = D_CALL;
- if(targ->dynimpname != nil && !(targ->cgoexport & CgoExportDynamic)) {
+ if(targ->type == SDYNIMPORT) {
addpltsym(targ);
r->sym = lookup(".plt", 0);
r->add = braddoff(r->add, targ->plt / 4);
return;
case 256 + R_ARM_ABS32:
- if(targ->dynimpname != nil && !(targ->cgoexport & CgoExportDynamic))
+ if(targ->type == SDYNIMPORT)
diag("unexpected R_ARM_ABS32 relocation for dynamic symbol %s", targ->name);
r->type = D_ADDR;
return;
case 256 + R_ARM_PC24:
case 256 + R_ARM_JUMP24:
r->type = D_CALL;
- if(targ->dynimpname != nil && !(targ->cgoexport & CgoExportDynamic)) {
+ if(targ->type == SDYNIMPORT) {
addpltsym(targ);
r->sym = lookup(".plt", 0);
r->add = braddoff(r->add, targ->plt / 4);
}
// Handle references to ELF symbols from our own object files.
- if(targ->dynimpname == nil || (targ->cgoexport & CgoExportDynamic))
+ if(targ->type != SDYNIMPORT)
return;
switch(r->type) {
if(s->dynid >= 0)
return;
- if(s->dynimpname == nil) {
- s->dynimpname = s->name;
- //diag("adddynsym: no dynamic name for %s", s->name);
- }
-
if(iself) {
s->dynid = nelfsym++;
d = lookup(".dynsym", 0);
/* name */
- name = s->dynimpname;
- if(name == nil)
- name = s->name;
+ name = s->extname;
adduint32(d, addstring(lookup(".dynstr", 0), name));
/* value */
adduint8(d, 0);
/* shndx */
- if(!(s->cgoexport & CgoExportDynamic) && s->dynimpname != nil)
+ if(s->type == SDYNIMPORT)
adduint16(d, SHN_UNDEF);
else {
switch(s->type) {
struct Sym
{
char* name;
+ char* extname; // name used in external object files
short type;
short version;
uchar dupok;
Sym* reachparent;
Sym* queue;
char* file;
- char* dynimpname;
char* dynimplib;
char* dynimpvers;
struct Section* sect;
// Handle relocations found in ELF object files.
case 256 + R_X86_64_PC32:
- if(targ->dynimpname != nil && !targ->cgoexport)
+ if(targ->type == SDYNIMPORT)
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);
case 256 + R_X86_64_PLT32:
r->type = D_PCREL;
r->add += 4;
- if(targ->dynimpname != nil && !targ->cgoexport) {
+ if(targ->type == SDYNIMPORT) {
addpltsym(targ);
r->sym = lookup(".plt", 0);
r->add += targ->plt;
return;
case 256 + R_X86_64_GOTPCREL:
- if(targ->dynimpname == nil || targ->cgoexport) {
+ if(targ->type != SDYNIMPORT) {
// have symbol
if(r->off >= 2 && s->p[r->off-2] == 0x8b) {
// turn MOVQ of GOT entry into LEAQ of symbol itself
}
// fall back to using GOT and hope for the best (CMOV*)
// TODO: just needs relocation, no need to put in .dynsym
- targ->dynimpname = targ->name;
}
addgotsym(targ);
r->type = D_PCREL;
return;
case 256 + R_X86_64_64:
- if(targ->dynimpname != nil && !targ->cgoexport)
+ if(targ->type == SDYNIMPORT)
diag("unexpected R_X86_64_64 relocation for dynamic symbol %s", targ->name);
r->type = D_ADDR;
return;
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)
+ if(targ->type == SDYNIMPORT)
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) {
+ if(targ->type == SDYNIMPORT) {
addpltsym(targ);
r->sym = lookup(".plt", 0);
r->add = targ->plt;
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)
+ if(targ->type == SDYNIMPORT)
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) {
+ if(targ->type != SDYNIMPORT) {
// have symbol
// turn MOVQ of GOT entry into LEAQ of symbol itself
if(r->off < 2 || s->p[r->off-2] != 0x8b) {
}
// fall through
case 512 + MACHO_X86_64_RELOC_GOT*2 + 1:
- if(targ->dynimpname == nil || targ->cgoexport)
+ if(targ->type != SDYNIMPORT)
diag("unexpected GOT reloc for non-dynamic symbol %s", targ->name);
addgotsym(targ);
r->type = D_PCREL;
}
// Handle references to ELF symbols from our own object files.
- if(targ->dynimpname == nil || targ->cgoexport)
+ if(targ->type != SDYNIMPORT)
return;
switch(r->type) {
if(s->dynid >= 0)
return;
- if(s->dynimpname == nil)
- diag("adddynsym: no dynamic name for %s", s->name);
-
if(iself) {
s->dynid = nelfsym++;
d = lookup(".dynsym", 0);
- name = s->dynimpname;
- if(name == nil)
- name = s->name;
+ name = s->extname;
adduint32(d, addstring(lookup(".dynstr", 0), name));
/* type */
t = STB_GLOBAL << 4;
adduint8(d, 0);
/* section where symbol is defined */
- if(!s->cgoexport && s->dynimpname != nil)
+ if(s->type == SDYNIMPORT)
adduint16(d, SHN_UNDEF);
else {
switch(s->type) {
addstring(lookup(".dynstr", 0), s->dynimplib));
}
} else if(HEADTYPE == Hdarwin) {
- diag("adddynsym: missed symbol %s (%s)", s->name, s->dynimpname);
+ diag("adddynsym: missed symbol %s (%s)", s->name, s->extname);
} else if(HEADTYPE == Hwindows) {
// already taken care of
} else {
struct Sym
{
char* name;
+ char* extname; // name used in external object files
short type;
short version;
uchar dupok;
vlong size;
Sym* gotype;
char* file;
- char* dynimpname;
char* dynimplib;
char* dynimpvers;
struct Section* sect;
// Handle relocations found in ELF object files.
case 256 + R_386_PC32:
- if(targ->dynimpname != nil && !targ->cgoexport)
+ if(targ->type == SDYNIMPORT)
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);
case 256 + R_386_PLT32:
r->type = D_PCREL;
r->add += 4;
- if(targ->dynimpname != nil && !targ->cgoexport) {
+ if(targ->type == SDYNIMPORT) {
addpltsym(targ);
r->sym = lookup(".plt", 0);
r->add += targ->plt;
return;
case 256 + R_386_GOT32:
- if(targ->dynimpname == nil || targ->cgoexport) {
+ if(targ->type != SDYNIMPORT) {
// have symbol
// turn MOVL of GOT entry into LEAL of symbol itself
if(r->off < 2 || s->p[r->off-2] != 0x8b) {
return;
case 256 + R_386_32:
- if(targ->dynimpname != nil && !targ->cgoexport)
+ if(targ->type == SDYNIMPORT)
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)
+ if(targ->type == SDYNIMPORT)
diag("unexpected reloc for dynamic symbol %s", targ->name);
return;
case 512 + MACHO_GENERIC_RELOC_VANILLA*2 + 1:
- if(targ->dynimpname != nil && !targ->cgoexport) {
+ if(targ->type == SDYNIMPORT) {
addpltsym(targ);
r->sym = lookup(".plt", 0);
r->add = targ->plt;
return;
case 512 + MACHO_FAKE_GOTPCREL:
- if(targ->dynimpname == nil || targ->cgoexport) {
+ if(targ->type != SDYNIMPORT) {
// have symbol
// turn MOVL of GOT entry into LEAL of symbol itself
if(r->off < 2 || s->p[r->off-2] != 0x8b) {
}
// Handle references to ELF symbols from our own object files.
- if(targ->dynimpname == nil || targ->cgoexport)
+ if(targ->type != SDYNIMPORT)
return;
switch(r->type) {
if(s->dynid >= 0)
return;
- if(s->dynimpname == nil)
- diag("adddynsym: no dynamic name for %s", s->name);
-
if(iself) {
s->dynid = nelfsym++;
d = lookup(".dynsym", 0);
/* name */
- name = s->dynimpname;
- if(name == nil)
- name = s->name;
+ name = s->extname;
adduint32(d, addstring(lookup(".dynstr", 0), name));
/* value */
adduint8(d, 0);
/* shndx */
- if(!s->cgoexport && s->dynimpname != nil)
+ if(s->type == SDYNIMPORT)
adduint16(d, SHN_UNDEF);
else {
switch(s->type) {
adduint16(d, t);
}
} else if(HEADTYPE == Hdarwin) {
- diag("adddynsym: missed symbol %s (%s)", s->name, s->dynimpname);
+ diag("adddynsym: missed symbol %s (%s)", s->name, s->extname);
} else if(HEADTYPE == Hwindows) {
// already taken care of
} else {
struct Sym
{
char* name;
+ char* extname; // name used in external object files
short type;
short version;
uchar dupok;
Sym* reachparent;
Sym* queue;
char* file;
- char* dynimpname;
char* dynimplib;
char* dynimpvers;
struct Section* sect;
for(r=s->r; r<s->r+s->nr; r++) {
if(r->sym != S && r->sym->type == SDYNIMPORT || r->type >= 256)
adddynrel(s, r);
- if(flag_shared && r->sym != S && (r->sym->dynimpname == nil || (r->sym->cgoexport & CgoExportDynamic)) && r->type == D_ADDR
+ if(flag_shared && r->sym != S && s->type != SDYNIMPORT && r->type == D_ADDR
&& (s == got || s->type == SDATA || s->type == SGOSTRING || s->type == STYPE || s->type == SRODATA)) {
// Create address based RELATIVE relocation
adddynrela(rel, s, r);
if(sy->dynimpvers)
need[sy->dynid] = addelflib(&needlib, sy->dynimplib, sy->dynimpvers);
- name = sy->dynimpname;
- if(name == nil)
- name = sy->name;
+ name = sy->extname;
hc = elfhash((uchar*)name);
b = hc % nbucket;
free(local);
if(s->type == 0 || s->type == SXREF) {
s->dynimplib = lib;
- s->dynimpname = remote;
+ s->extname = remote;
s->dynimpvers = q;
s->type = SDYNIMPORT;
havedynamic = 1;
nerrors++;
}
- if(strcmp(f[0], "cgo_export_static") == 0)
- s->cgoexport |= CgoExportStatic;
- else
- s->cgoexport |= CgoExportDynamic;
- if(s->dynimpname == nil) {
- s->dynimpname = remote;
+ if(s->cgoexport == 0) {
+ if(strcmp(f[0], "cgo_export_static") == 0)
+ s->cgoexport |= CgoExportStatic;
+ else
+ s->cgoexport |= CgoExportDynamic;
+ s->extname = remote;
if(ndynexp%32 == 0)
dynexp = erealloc(dynexp, (ndynexp+32)*sizeof dynexp[0]);
dynexp[ndynexp++] = s;
- } else if(strcmp(s->dynimpname, remote) != 0) {
- fprint(2, "%s: conflicting cgo_export directives: %s as %s and %s\n", argv0, s->name, s->dynimpname, remote);
+ } else if(strcmp(s->extname, remote) != 0) {
+ fprint(2, "%s: conflicting cgo_export directives: %s as %s and %s\n", argv0, s->name, s->extname, remote);
nerrors++;
return;
}
s->sub = sect->sym->sub;
sect->sym->sub = s;
s->type = sect->sym->type | (s->type&~SMASK) | SSUB;
- if(!(s->cgoexport & CgoExportDynamic)) {
+ if(!(s->cgoexport & CgoExportDynamic))
s->dynimplib = nil; // satisfy dynimport
- s->dynimpname = nil; // satisfy dynimport
- }
s->value = sym.value;
s->size = sym.size;
s->outer = sect->sym;
s->size = (sym+1)->value - sym->value;
else
s->size = sect->addr + sect->size - sym->value;
- if(!(s->cgoexport & CgoExportDynamic)) {
+ if(!(s->cgoexport & CgoExportDynamic))
s->dynimplib = nil; // satisfy dynimport
- s->dynimpname = nil; // satisfy dynimport
- }
if(outer->type == STEXT) {
Prog *p;
return nil;
s = newsym(symb, v);
+ s->extname = s->name;
s->hash = hash[h];
hash[h] = s;
{
if(s->type == SDYNIMPORT)
return SymKindUndef;
- if(s->dynimpname)
+ if(s->cgoexport)
return SymKindExtdef;
return SymKindLocal;
}
}
nsortsym++;
}
-
-static char*
-xsymname(Sym *s)
-{
- if(s->dynimpname != nil)
- return s->dynimpname;
- return s->name;
-}
static int
scmp(const void *p1, const void *p2)
if(k1 != k2)
return k1 - k2;
- return strcmp(xsymname(s1), xsymname(s2));
+ return strcmp(s1->extname, s2->extname);
}
static void
s = sortsym[i];
adduint32(symtab, symstr->size);
adduint8(symstr, '_');
- addstring(symstr, xsymname(s));
+ addstring(symstr, s->extname);
if(s->type == SDYNIMPORT) {
adduint8(symtab, 0x01); // type N_EXT, external symbol
adduint8(symtab, 0); // no section
dr = nil;
m = nil;
for(s = allsym; s != S; s = s->allsym) {
- if(!s->reachable || !s->dynimpname || (s->cgoexport & CgoExportDynamic))
+ if(!s->reachable || s->type != SDYNIMPORT)
continue;
for(d = dr; d != nil; d = d->next) {
if(strcmp(d->name,s->dynimplib) == 0) {
for(m = d->ms; m != nil; m = m->next) {
m->off = nextsectoff + cpos() - startoff;
wputl(0); // hint
- strput(m->s->dynimpname);
+ strput(m->s->extname);
}
}
s1 = *(Sym**)p1;
s2 = *(Sym**)p2;
- return strcmp(s1->dynimpname, s2->dynimpname);
+ return strcmp(s1->extname, s2->extname);
}
static void
nexport = 0;
for(s = allsym; s != S; s = s->allsym) {
- if(!s->reachable || !s->dynimpname || !(s->cgoexport & CgoExportDynamic))
+ if(!s->reachable || !(s->cgoexport & CgoExportDynamic))
continue;
if(nexport+1 > sizeof(dexport)/sizeof(dexport[0])) {
diag("pe dynexport table is full");
size = sizeof e + 10*nexport + strlen(outfile) + 1;
for(i=0; i<nexport; i++)
- size += strlen(dexport[i]->dynimpname) + 1;
+ size += strlen(dexport[i]->extname) + 1;
if (nexport == 0)
return;
v = e.Name + strlen(outfile)+1;
for(i=0; i<nexport; i++) {
lputl(v);
- v += strlen(dexport[i]->dynimpname)+1;
+ v += strlen(dexport[i]->extname)+1;
}
// put EXPORT Ordinal Table
for(i=0; i<nexport; i++)
// put Names
strnput(outfile, strlen(outfile)+1);
for(i=0; i<nexport; i++)
- strnput(dexport[i]->dynimpname, strlen(dexport[i]->dynimpname)+1);
+ strnput(dexport[i]->extname, strlen(dexport[i]->extname)+1);
strnput("", sect->SizeOfRawData - size);
}