Clean up more code

- Found some bugs in LLVM compiler-rt library
- The useless LIBC_STUBS package is now deleted
- Improve the overflow checking story even further
- Get chibicc tests working in MODE=dbg mode again
- The libc/isystem/ headers now have correctly named guards
This commit is contained in:
Justine Tunney 2023-06-18 00:55:09 -07:00
parent afc58a8b41
commit d7c79f43ef
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
294 changed files with 912 additions and 1208 deletions

View file

@ -19,14 +19,23 @@
#include "libc/elf/elf.h"
#include "libc/stdckdint.h"
// note: should not be used on bss section
/**
* Returns pointer to elf section file content.
*
* This function shouldn't be used on the bss section.
*
* @param elf points to the start of the executable image
* @param mapsize is the number of bytes past `elf` we can access
* @param shdr is from GetElfSectionHeaderAddress() and null-propagating
* @return pointer to content bytes, or null on error
*/
void *GetElfSectionAddress(const Elf64_Ehdr *elf, // validated
size_t mapsize, // validated
const Elf64_Shdr *shdr) { // foreign
uint64_t addr, last;
uint64_t last;
if (!shdr) return 0;
if (ckd_add(&addr, (uintptr_t)elf, shdr->sh_offset)) return 0;
if (ckd_add(&last, addr, shdr->sh_size)) return 0;
if (last > (uintptr_t)elf + mapsize) return 0;
return (void *)addr;
if (shdr->sh_size <= 0) return 0;
if (ckd_add(&last, shdr->sh_offset, shdr->sh_size)) return 0;
if (last > mapsize) return 0;
return (char *)elf + shdr->sh_offset;
}