int32 v, magic;
int a, nl;
uchar *op1;
- vlong vl, va, startva, fo, w, symo, hashoff;
+ vlong vl, va, startva, fo, w, symo, hashoff, dstrtab, off;
vlong symdatva = 0x99LL<<32;
Elf64Hdr *eh;
Elf64PHdr *ph, *pph;
sh = newElf64SHdr("");
pph = nil; /* silence compiler */
+ dstrtab = 0;
/* Dynamic linking sections */
if (!debug['d']) { /* -d suppresses dynamic loader format */
pph->off = ELF64HDRSIZE;
pph->vaddr = startva + pph->off;
pph->paddr = startva + pph->off;
- pph->align = 8;
+ pph->align = INITRND;
/* interpreter */
ph = newElf64PHdr();
sh->addr = startva + sh->off;
sh->off = startelf();
elf64writedynent(DT_HASH, startva+hashoff);
- elf64writedynent(DT_STRTAB, startva+ELF64FULLHDRSIZE-STRTABSIZE);
elf64writedynent(DT_SYMTAB, startva);
elf64writedynent(DT_RELA, startva);
elf64writedynent(DT_RELASZ, 0); // size of the whole rela in bytes
elf64writedynent(DT_RELAENT, ELF64RELASIZE);
- elf64writedynent(DT_STRSZ, STRTABSIZE);
elf64writedynent(DT_SYMENT, 0);
+// elf64writedynent(DT_NEEDED, elf64addstr("libc.so.6"));
+
+ /* make space for these now but fill them in later */
+ cflush();
+ dstrtab = seek(cout, 0, 1);
+ elf64writedynent(DT_STRTAB, -1);
+ elf64writedynent(DT_STRSZ, -1);
+
elf64writedynent(DT_NULL, 0);
sh->size = endelf() - sh->off;
sh->addralign = 8;
ph->paddr = startva + ph->off;
ph->filesz = sh->off + sh->size - ph->off;
ph->memsz = ph->filesz;
- ph->align = 8;
+ ph->align = INITRND;
}
ph = newElf64PHdr();
elf64writestrtable();
sh->size = endelf() - sh->off;
+ if(dstrtab != 0) {
+ // update DT_STRTAB entry
+ cflush();
+ off = seek(cout, 0, 1);
+ seek(cout, dstrtab, 0);
+ elf64writedynent(DT_STRTAB, sh->addr);
+ elf64writedynent(DT_STRSZ, sh->size);
+ cflush();
+ seek(cout, off, 0);
+ }
+
/* Main header */
eh = getElf64Hdr();
eh->ident[EI_MAG0] = '\177';
static Elf64PHdr *phdr[NSECT];
static Elf64SHdr *shdr[NSECT];
static char *sname[NSECT];
-static char *str[NSECT];
+static char *str[20];
/*
Initialize the global variable that describes the ELF header. It will be updated as
diag("elf64 string table overflow");
}
-void
-e64addstr(char *name)
+uint32
+elf64addstr(char *name)
{
- if (numstr >= NSECT) {
+ int r;
+
+ if (numstr >= nelem(str)) {
diag("too many elf strings");
- return;
+ return 0;
}
str[numstr++] = strdup(name);
+ r = stroffset;
stroffset += strlen(name)+1;
+ return r;
}
uint32
hdr.shstrndx = hdr.shnum;
e = malloc(sizeof *e);
memset(e, 0, sizeof *e);
- e->name = stroffset;
+ e->name = elf64addstr(name);
if (hdr.shnum >= NSECT) {
diag("too many shdrs");
} else {
- e64addstr(name);
shdr[hdr.shnum++] = e;
}
return e;
}
uint32
-elf64writehdr()
+elf64writehdr(void)
{
int i;