Rewrite Cosmopolitan Ar

The build/bootstrap/ar.com program is now tinier. This change reduces
its size from 140kb to 53kb. Nothing was traded away. Cosmopolitan Ar
performance is now 2x better than llvm-ar largely thanks to using the
copy_file_range() system call. This change homebrews a new allocation
API that addresses the shortcomings of the C standard library design.
Using these new balloc() and reballoc() functions I managed to reduce
memory consumption so much that Cosmpolitan Ar should now use roughly
100x fewer bytes of peak resident memory compared to llvm-ar. Correct
behavior with better compatibility has been assured. Binary output is
now pretty much bit-identical to llvm-ar, as of this change. This can
and should be the living proof we need to show that a better world is
possible for software.
This commit is contained in:
Justine Tunney 2023-07-02 10:19:16 -07:00
parent 197aa0d465
commit 0c630d95b5
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
27 changed files with 916 additions and 341 deletions

View file

@ -3,15 +3,55 @@
#include "libc/elf/scalar.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
/*
* ELF relocation w/ explicit addend.
*
* Relocations let us easily apply fixups to compiled object code. This
* data structure represents the contents of an `sh_type` w/ `SHT_RELA`
*
* @see Elf64_Rel
*/
typedef struct Elf64_Rela {
/*u64*/ Elf64_Addr r_offset;
/*
* ELF64_R_SYM(r_info) sym
* ELF64_R_TYPE(r_info) R_X86_64_{64,PC32,GOTPCRELX,...}
* ELF64_R_INFO(sym, type) r_info
* Location to be modified.
*
* If `e_type` is `ET_REL` then this is a section data byte offset.
*
* If `e_type` isn't `ET_REL` then this is a virtual address.
*/
/*u64*/ Elf64_Xword r_info; /* ELF64_R_{SYM,SIZE,INFO} */
/*i64*/ Elf64_Sxword r_addend;
Elf64_Addr r_offset;
/*
* Relocation type and symbol.
*
* This value may be created using:
*
* r_info = ELF64_R_INFO(sym, type);
*
* This value may be read using:
*
* Elf64_Word sym = ELF64_R_SYM(r_info);
* Elf64_Word type = ELF64_R_TYPE(r_info);
*
* Where `sym` is a symbol index, and `type` might be:
*
* - `R_X86_64_64`
* - `R_X86_64_PC32`
* - `R_X86_64_GOTPCRELX`
* - `R_AARCH64_ABS64`
*
*/
Elf64_Xword r_info;
/*
* Relocation parameter.
*
* Each relocation type has its own mathematical formula, which should
* incorporate this value in its own unique way.
*/
Elf64_Sxword r_addend;
} Elf64_Rela;
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */