mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-03 17:58:30 +00:00
Get llama.com building as an aarch64 native binary
This commit is contained in:
parent
d04430f4ef
commit
4c093155a3
40 changed files with 7842 additions and 11683 deletions
|
@ -16,6 +16,7 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "tool/build/lib/elfwriter.h"
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/elf/def.h"
|
||||
|
@ -30,7 +31,6 @@
|
|||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
#include "libc/x/xasprintf.h"
|
||||
#include "tool/build/lib/elfwriter.h"
|
||||
|
||||
static const Elf64_Ehdr kObjHeader = {
|
||||
.e_ident = {ELFMAG0, ELFMAG1, ELFMAG2, ELFMAG3, ELFCLASS64, ELFDATA2LSB, 1,
|
||||
|
@ -166,6 +166,15 @@ struct ElfWriter *elfwriter_open(const char *path, int mode) {
|
|||
elf->mapsize, PROT_READ | PROT_WRITE,
|
||||
MAP_SHARED | MAP_FIXED, elf->fd, 0)));
|
||||
elf->ehdr = memcpy(elf->map, &kObjHeader, (elf->wrote = sizeof(kObjHeader)));
|
||||
if (strstr(path, "/aarch64")) {
|
||||
elf->ehdr->e_machine = EM_AARCH64;
|
||||
} else if (strstr(path, "/powerpc64")) {
|
||||
elf->ehdr->e_machine = EM_PPC64;
|
||||
} else if (strstr(path, "/riscv")) {
|
||||
elf->ehdr->e_machine = EM_RISCV;
|
||||
} else if (strstr(path, "/s390")) {
|
||||
elf->ehdr->e_machine = EM_S390;
|
||||
}
|
||||
elf->strtab = newinterner();
|
||||
elf->shstrtab = newinterner();
|
||||
intern(elf->strtab, "");
|
||||
|
@ -274,3 +283,20 @@ void elfwriter_appendrela(struct ElfWriter *elf, uint64_t r_offset,
|
|||
.offset = r_offset,
|
||||
.addend = r_addend})));
|
||||
}
|
||||
|
||||
uint32_t elfwriter_relatype_abs32(const struct ElfWriter *elf) {
|
||||
switch (elf->ehdr->e_machine) {
|
||||
case EM_NEXGEN32E:
|
||||
return R_X86_64_32;
|
||||
case EM_AARCH64:
|
||||
return R_AARCH64_ABS32;
|
||||
case EM_PPC64:
|
||||
return R_PPC64_ADDR32;
|
||||
case EM_RISCV:
|
||||
return R_RISCV_32;
|
||||
case EM_S390:
|
||||
return R_390_32;
|
||||
default:
|
||||
notpossible;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,6 +64,7 @@ void elfwriter_commit(struct ElfWriter *, size_t);
|
|||
void elfwriter_finishsection(struct ElfWriter *);
|
||||
void elfwriter_appendrela(struct ElfWriter *, uint64_t, struct ElfWriterSymRef,
|
||||
uint32_t, int64_t);
|
||||
uint32_t elfwriter_relatype_abs32(const struct ElfWriter *);
|
||||
struct ElfWriterSymRef elfwriter_linksym(struct ElfWriter *, const char *, int,
|
||||
int);
|
||||
struct ElfWriterSymRef elfwriter_appendsym(struct ElfWriter *, const char *,
|
||||
|
|
|
@ -27,6 +27,7 @@ void elfwriter_yoink(struct ElfWriter *elf, const char *symbol, int stb) {
|
|||
memcpy(p, kNopl, sizeof(kNopl));
|
||||
sym = elfwriter_linksym(elf, symbol, ELF64_ST_INFO(stb, STT_OBJECT),
|
||||
STV_HIDDEN);
|
||||
elfwriter_appendrela(elf, sizeof(kNopl) - 4, sym, R_X86_64_32, 0);
|
||||
elfwriter_appendrela(elf, sizeof(kNopl) - 4, sym,
|
||||
elfwriter_relatype_abs32(elf), 0);
|
||||
elfwriter_commit(elf, sizeof(kNopl));
|
||||
}
|
||||
|
|
|
@ -215,8 +215,8 @@ void elfwriter_zip(struct ElfWriter *elf, const char *symbol, const char *name,
|
|||
elfwriter_appendsym(elf, _gc(xasprintf("%s%s", "zip+cdir:", name)),
|
||||
ELF64_ST_INFO(STB_LOCAL, STT_OBJECT), STV_DEFAULT, 0,
|
||||
kZipCdirHdrLinkableSizeBootstrap);
|
||||
elfwriter_appendrela(elf, kZipCfileOffsetOffset, lfilesym, R_X86_64_32,
|
||||
-imagebase);
|
||||
elfwriter_appendrela(elf, kZipCfileOffsetOffset, lfilesym,
|
||||
elfwriter_relatype_abs32(elf), -imagebase);
|
||||
elfwriter_commit(elf, kZipCdirHdrLinkableSizeBootstrap);
|
||||
elfwriter_finishsection(elf);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue