mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-01 00:38:31 +00:00
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:
parent
197aa0d465
commit
0c630d95b5
27 changed files with 916 additions and 341 deletions
|
@ -16,21 +16,29 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/elf/def.h"
|
||||
#include "libc/elf/elf.h"
|
||||
#include "libc/elf/scalar.h"
|
||||
#include "libc/elf/struct/shdr.h"
|
||||
|
||||
/**
|
||||
* Returns section header object at `elf.section[i]`.
|
||||
*
|
||||
* @param elf points to the start of the executable image
|
||||
* @param elf points to the start of the executable image data
|
||||
* @param mapsize is the number of bytes past `elf` we can access
|
||||
* @param i is the section header index, starting at zero
|
||||
* @return section header pointer, or null on error
|
||||
* @param i is the index of the section header
|
||||
* @return pointer to section header within image, or null if
|
||||
* 1. `i` was a magic number, i.e. `i >= SHN_LORESERVE`, or
|
||||
* 2. `e_shoff` was zero (image has no section headers), or
|
||||
* 3. `e_shentsize` had fewer than the mandatory 60 bytes, or
|
||||
* 4. section header wasn't contained by `[elf,elf+mapsize)`, or
|
||||
* 5. an arithmetic overflow occurred
|
||||
*/
|
||||
Elf64_Shdr *GetElfSectionHeaderAddress(const Elf64_Ehdr *elf, //
|
||||
size_t mapsize, //
|
||||
Elf64_Half i) { //
|
||||
uint64_t off;
|
||||
Elf64_Off off;
|
||||
if (i >= SHN_LORESERVE) return 0;
|
||||
if (i >= elf->e_shnum) return 0;
|
||||
if (elf->e_shoff <= 0) return 0;
|
||||
if (elf->e_shoff >= mapsize) return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue