cmd/5l, cmd/ld: support generating ELF binaries for NetBSD/ARM

R=golang-dev, dave
CC=golang-dev
https://golang.org/cl/7261043
This commit is contained in:
Shenghou Ma 2013-02-04 00:40:11 +08:00
parent 848d10f06c
commit 2ebfaa36b5
3 changed files with 20 additions and 25 deletions

View file

@ -40,7 +40,7 @@ static Prog *PP;
char linuxdynld[] = "/lib/ld-linux.so.3"; // 2 for OABI, 3 for EABI char linuxdynld[] = "/lib/ld-linux.so.3"; // 2 for OABI, 3 for EABI
char freebsddynld[] = "/usr/libexec/ld-elf.so.1"; char freebsddynld[] = "/usr/libexec/ld-elf.so.1";
char openbsddynld[] = "XXX"; char openbsddynld[] = "XXX";
char netbsddynld[] = "XXX"; char netbsddynld[] = "/libexec/ld.elf_so";
int32 int32
entryvalue(void) entryvalue(void)
@ -581,9 +581,6 @@ asmb(void)
case Hplan9x32: case Hplan9x32:
symo = HEADR+segtext.len+segdata.filelen; symo = HEADR+segtext.len+segdata.filelen;
break; break;
case Hnetbsd:
symo = rnd(segdata.filelen, 4096);
break;
ElfSym: ElfSym:
symo = rnd(HEADR+segtext.filelen, INITRND)+segdata.filelen; symo = rnd(HEADR+segtext.filelen, INITRND)+segdata.filelen;
symo = rnd(symo, INITRND); symo = rnd(symo, INITRND);

View file

@ -48,21 +48,22 @@ Header headers[] = {
"noheader", Hnoheader, "noheader", Hnoheader,
"risc", Hrisc, "risc", Hrisc,
"plan9", Hplan9x32, "plan9", Hplan9x32,
"netbsd", Hnetbsd,
"ixp1200", Hixp1200, "ixp1200", Hixp1200,
"ipaq", Hipaq, "ipaq", Hipaq,
"linux", Hlinux, "linux", Hlinux,
"freebsd", Hfreebsd, "freebsd", Hfreebsd,
"netbsd", Hnetbsd,
0, 0 0, 0
}; };
/* /*
* -Hrisc -T0x10005000 -R4 is aif for risc os * -Hrisc -T0x10005000 -R4 is aif for risc os
* -Hplan9 -T4128 -R4096 is plan9 format * -Hplan9 -T4128 -R4096 is plan9 format
* -Hnetbsd -T0xF0000020 -R4 is NetBSD format
* -Hixp1200 is IXP1200 (raw) * -Hixp1200 is IXP1200 (raw)
* -Hipaq -T0xC0008010 -R1024 is ipaq * -Hipaq -T0xC0008010 -R1024 is ipaq
* -Hlinux -Tx -Rx is linux elf * -Hlinux -Tx -Rx is linux elf
* -Hfreebsd is freebsd elf
* -Hnetbsd is netbsd elf
*/ */
void void
@ -166,15 +167,6 @@ main(int argc, char *argv[])
if(INITRND == -1) if(INITRND == -1)
INITRND = 4096; INITRND = 4096;
break; break;
case Hnetbsd: /* boot for NetBSD */
HEADR = 32L;
if(INITTEXT == -1)
INITTEXT = 0xF0000020L;
if(INITDAT == -1)
INITDAT = 0;
if(INITRND == -1)
INITRND = 4096;
break;
case Hixp1200: /* boot for IXP1200 */ case Hixp1200: /* boot for IXP1200 */
HEADR = 0L; HEADR = 0L;
if(INITTEXT == -1) if(INITTEXT == -1)
@ -195,6 +187,7 @@ main(int argc, char *argv[])
break; break;
case Hlinux: /* arm elf */ case Hlinux: /* arm elf */
case Hfreebsd: case Hfreebsd:
case Hnetbsd:
debug['d'] = 0; // with dynamic linking debug['d'] = 0; // with dynamic linking
tlsoffset = -8; // hardcoded number, first 4-byte word for g, and then 4-byte word for m tlsoffset = -8; // hardcoded number, first 4-byte word for g, and then 4-byte word for m
// this number is known to ../../pkg/runtime/cgo/gcc_linux_arm.c // this number is known to ../../pkg/runtime/cgo/gcc_linux_arm.c

View file

@ -55,7 +55,9 @@ elfinit(void)
// 32-bit architectures // 32-bit architectures
case '5': case '5':
hdr.flags = 0x5000002; // has entry point, Version5 EABI // we only use EABI on linux/arm
if(HEADTYPE == Hlinux)
hdr.flags = 0x5000002; // has entry point, Version5 EABI
// fallthrough // fallthrough
default: default:
hdr.phoff = ELF32HDRSIZE; /* Must be be ELF32HDRSIZE: first PHdr must follow ELF header */ hdr.phoff = ELF32HDRSIZE; /* Must be be ELF32HDRSIZE: first PHdr must follow ELF header */
@ -1303,6 +1305,7 @@ asmbelf(vlong symo)
sh->type = SHT_REL; sh->type = SHT_REL;
sh->flags = SHF_ALLOC; sh->flags = SHF_ALLOC;
sh->entsize = ELF32RELSIZE; sh->entsize = ELF32RELSIZE;
sh->link = elfshname(".dynsym")->shnum;
shsym(sh, lookup(".rel.plt", 0)); shsym(sh, lookup(".rel.plt", 0));
sh = elfshname(".rel"); sh = elfshname(".rel");
@ -1375,15 +1378,17 @@ asmbelf(vlong symo)
} }
} }
ph = newElfPhdr(); if(HEADTYPE == Hlinux) {
ph->type = PT_GNU_STACK; ph = newElfPhdr();
ph->flags = PF_W+PF_R; ph->type = PT_GNU_STACK;
ph->align = PtrSize; ph->flags = PF_W+PF_R;
ph->align = PtrSize;
ph = newElfPhdr();
ph->type = PT_PAX_FLAGS; ph = newElfPhdr();
ph->flags = 0x2a00; // mprotect, randexec, emutramp disabled ph->type = PT_PAX_FLAGS;
ph->align = PtrSize; ph->flags = 0x2a00; // mprotect, randexec, emutramp disabled
ph->align = PtrSize;
}
elfobj: elfobj:
sh = elfshname(".shstrtab"); sh = elfshname(".shstrtab");