mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-04 02:08:30 +00:00
Apply clang-format update to repo (#1154)
Commit bc6c183
introduced a bunch of discrepancies between what files
look like in the repo and what clang-format says they should look like.
However, there were already a few discrepancies prior to that. Most of
these discrepancies seemed to be unintentional, but a few of them were
load-bearing (e.g., a #include that violated header ordering needing
something to have been #defined by a 'later' #include.)
I opted to take what I hope is a relatively smooth-brained approach: I
reverted the .clang-format change, ran clang-format on the whole repo,
reapplied the .clang-format change, reran clang-format again, and then
reverted the commit that contained the first run. Thus the full effect
of this PR should only be to apply the changed formatting rules to the
repo, and from skimming the results, this seems to be the case.
My work can be checked by applying the short, manual commits, and then
rerunning the command listed in the autogenerated commits (those whose
messages I have prefixed auto:) and seeing if your results agree.
It might be that the other diffs should be fixed at some point but I'm
leaving that aside for now.
fd '\.c(c|pp)?$' --print0| xargs -0 clang-format -i
This commit is contained in:
parent
342d0c81e5
commit
6e6fc38935
863 changed files with 9201 additions and 4627 deletions
|
@ -78,18 +78,21 @@ static wontreturn void DieOom(void) {
|
|||
|
||||
static void *Malloc(size_t n) {
|
||||
void *p;
|
||||
if (!(p = malloc(n))) DieOom();
|
||||
if (!(p = malloc(n)))
|
||||
DieOom();
|
||||
return p;
|
||||
}
|
||||
|
||||
static void *Realloc(void *p, size_t n) {
|
||||
if (!(p = realloc(p, n))) DieOom();
|
||||
if (!(p = realloc(p, n)))
|
||||
DieOom();
|
||||
return p;
|
||||
}
|
||||
|
||||
static wontreturn void SysExit(const char *func) {
|
||||
const char *errstr;
|
||||
if (!(errstr = _strerdoc(errno))) errstr = "EUNKNOWN";
|
||||
if (!(errstr = _strerdoc(errno)))
|
||||
errstr = "EUNKNOWN";
|
||||
tinyprint(2, epath, ": ", func, " failed with ", errstr, "\n", NULL);
|
||||
exit(1);
|
||||
}
|
||||
|
@ -201,11 +204,15 @@ static const unsigned char kNops[10][10] = {
|
|||
static unsigned char *CoalesceNops(unsigned char *p, const unsigned char *e) {
|
||||
long n;
|
||||
for (; p + 1 < e; p += n) {
|
||||
if (p[0] != 0x90) break;
|
||||
if (p[1] != 0x90) break;
|
||||
if (p[0] != 0x90)
|
||||
break;
|
||||
if (p[1] != 0x90)
|
||||
break;
|
||||
for (n = 2; p + n < e; ++n) {
|
||||
if (p[n] != 0x90) break;
|
||||
if (n == ARRAYLEN(kNops) - 1) break;
|
||||
if (p[n] != 0x90)
|
||||
break;
|
||||
if (n == ARRAYLEN(kNops) - 1)
|
||||
break;
|
||||
}
|
||||
memcpy(p, kNops[n], n);
|
||||
}
|
||||
|
@ -218,16 +225,23 @@ static void CheckPrivilegedCrossReferences(void) {
|
|||
const Elf64_Shdr *shdr;
|
||||
const Elf64_Rela *rela, *erela;
|
||||
shdr = FindElfSectionByName(elf, esize, secstrs, ".rela.privileged");
|
||||
if (!shdr || !(rela = GetElfSectionAddress(elf, esize, shdr))) return;
|
||||
if (!shdr || !(rela = GetElfSectionAddress(elf, esize, shdr)))
|
||||
return;
|
||||
erela = rela + shdr->sh_size / sizeof(*rela);
|
||||
for (; rela < erela; ++rela) {
|
||||
if (!ELF64_R_TYPE(rela->r_info)) continue;
|
||||
if (!(x = ELF64_R_SYM(rela->r_info))) continue;
|
||||
if (x >= symcount) continue;
|
||||
if (syms[x].st_shndx == SHN_ABS) continue;
|
||||
if (!syms[x].st_shndx) continue;
|
||||
if (!ELF64_R_TYPE(rela->r_info))
|
||||
continue;
|
||||
if (!(x = ELF64_R_SYM(rela->r_info)))
|
||||
continue;
|
||||
if (x >= symcount)
|
||||
continue;
|
||||
if (syms[x].st_shndx == SHN_ABS)
|
||||
continue;
|
||||
if (!syms[x].st_shndx)
|
||||
continue;
|
||||
if ((shdr = GetElfSectionHeaderAddress(elf, esize, syms[x].st_shndx))) {
|
||||
if (~shdr->sh_flags & SHF_EXECINSTR) continue; // data reference
|
||||
if (~shdr->sh_flags & SHF_EXECINSTR)
|
||||
continue; // data reference
|
||||
if ((secname = GetElfString(elf, esize, secstrs, shdr->sh_name)) &&
|
||||
strcmp(".privileged", secname)) {
|
||||
tinyprint(2, epath,
|
||||
|
@ -334,12 +348,15 @@ static void OptimizePatchableFunctionEntries(void) {
|
|||
Elf64_Addr sym_rva;
|
||||
if (elf->e_machine == EM_NEXGEN32E) {
|
||||
for (i = 0; i < symcount; ++i) {
|
||||
if (!syms[i].st_size) continue;
|
||||
if (ELF64_ST_TYPE(syms[i].st_info) != STT_FUNC) continue;
|
||||
if (!syms[i].st_size)
|
||||
continue;
|
||||
if (ELF64_ST_TYPE(syms[i].st_info) != STT_FUNC)
|
||||
continue;
|
||||
if (!(shdr = GetElfSectionHeaderAddress(elf, esize, syms[i].st_shndx))) {
|
||||
Die("elf header overflow #3");
|
||||
}
|
||||
if (shdr->sh_type != SHT_PROGBITS) continue;
|
||||
if (shdr->sh_type != SHT_PROGBITS)
|
||||
continue;
|
||||
if (!(p = GetElfSectionAddress(elf, esize, shdr))) {
|
||||
Die("elf section overflow");
|
||||
}
|
||||
|
@ -371,7 +388,8 @@ static void RelinkZipFiles(void) {
|
|||
// scan backwards for zip eocd todo record
|
||||
// that was created by libc/nexgen32e/zip.S
|
||||
for (;;) {
|
||||
if (eocd < stop) return;
|
||||
if (eocd < stop)
|
||||
return;
|
||||
if (READ32LE(eocd) == kZipCdirHdrMagicTodo && //
|
||||
ZIP_CDIR_SIZE(eocd) && //
|
||||
!ZIP_CDIR_OFFSET(eocd) && //
|
||||
|
@ -446,13 +464,17 @@ static void GenerateIfuncInit(void) {
|
|||
static char code[16384];
|
||||
static Elf64_Rela relas[1024];
|
||||
Elf64_Shdr *symtab_shdr = GetElfSymbolTable(elf, esize, SHT_SYMTAB, 0);
|
||||
if (!symtab_shdr) Die("symbol table section header not found");
|
||||
if (!symtab_shdr)
|
||||
Die("symbol table section header not found");
|
||||
Elf64_Word symtab_shdr_index =
|
||||
((char *)symtab_shdr - ((char *)elf + elf->e_shoff)) / elf->e_shentsize;
|
||||
for (Elf64_Xword i = 0; i < symcount; ++i) {
|
||||
if (syms[i].st_shndx == SHN_UNDEF) continue;
|
||||
if (syms[i].st_shndx >= SHN_LORESERVE) continue;
|
||||
if (ELF64_ST_TYPE(syms[i].st_info) != STT_GNU_IFUNC) continue;
|
||||
if (syms[i].st_shndx == SHN_UNDEF)
|
||||
continue;
|
||||
if (syms[i].st_shndx >= SHN_LORESERVE)
|
||||
continue;
|
||||
if (ELF64_ST_TYPE(syms[i].st_info) != STT_GNU_IFUNC)
|
||||
continue;
|
||||
if (!(name = GetElfString(elf, esize, symstrs, syms[i].st_name)))
|
||||
Die("could not get symbol name of ifunc");
|
||||
static char resolver_name[65536];
|
||||
|
@ -463,11 +485,16 @@ static void GenerateIfuncInit(void) {
|
|||
Elf64_Xword function_sym_index = i;
|
||||
Elf64_Xword resolver_sym_index = -1;
|
||||
for (Elf64_Xword i = 0; i < symcount; ++i) {
|
||||
if (syms[i].st_shndx == SHN_UNDEF) continue;
|
||||
if (syms[i].st_shndx >= SHN_LORESERVE) continue;
|
||||
if (ELF64_ST_TYPE(syms[i].st_info) != STT_FUNC) continue;
|
||||
if (!(s = GetElfString(elf, esize, symstrs, syms[i].st_name))) continue;
|
||||
if (strcmp(s, resolver_name)) continue;
|
||||
if (syms[i].st_shndx == SHN_UNDEF)
|
||||
continue;
|
||||
if (syms[i].st_shndx >= SHN_LORESERVE)
|
||||
continue;
|
||||
if (ELF64_ST_TYPE(syms[i].st_info) != STT_FUNC)
|
||||
continue;
|
||||
if (!(s = GetElfString(elf, esize, symstrs, syms[i].st_name)))
|
||||
continue;
|
||||
if (strcmp(s, resolver_name))
|
||||
continue;
|
||||
resolver_sym_index = i;
|
||||
break;
|
||||
}
|
||||
|
@ -521,15 +548,18 @@ static void GenerateIfuncInit(void) {
|
|||
0x5e, // pop %rsi
|
||||
0x5f, // pop %rdi
|
||||
};
|
||||
if (code_i + sizeof(chunk3) > sizeof(code)) Die("too many ifuncs");
|
||||
if (code_i + sizeof(chunk3) > sizeof(code))
|
||||
Die("too many ifuncs");
|
||||
memcpy(code + code_i, chunk3, sizeof(chunk3));
|
||||
code_i += sizeof(chunk3);
|
||||
}
|
||||
if (!code_i) return;
|
||||
if (!code_i)
|
||||
return;
|
||||
|
||||
// prepare to mutate elf
|
||||
// remap file so it has more space
|
||||
if (elf->e_shnum + 2 > 65535) Die("too many sections");
|
||||
if (elf->e_shnum + 2 > 65535)
|
||||
Die("too many sections");
|
||||
size_t reserve_size = esize + 32 * 1024 * 1024;
|
||||
elf = Realloc(elf, reserve_size);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue