Skip to content

Commit

Permalink
Fix unzip warning with apelink generated symtabs
Browse files Browse the repository at this point in the history
  • Loading branch information
jart committed Nov 19, 2023
1 parent 3e6d536 commit 0c89516
Show file tree
Hide file tree
Showing 17 changed files with 192 additions and 59 deletions.
2 changes: 1 addition & 1 deletion libc/str/getzipcfilecompressedsize.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int64_t GetZipCfileCompressedSize(const uint8_t *z) {
}
const uint8_t *p = ZIP_CFILE_EXTRA(z);
const uint8_t *pe = p + ZIP_CFILE_EXTRASIZE(z);
for (; p < pe; p += ZIP_EXTRA_SIZE(p)) {
for (; p + ZIP_EXTRA_SIZE(p) <= pe; p += ZIP_EXTRA_SIZE(p)) {
if (ZIP_EXTRA_HEADERID(p) == kZipExtraZip64) {
if (8 <= ZIP_EXTRA_CONTENTSIZE(p)) {
return READ64LE(ZIP_EXTRA_CONTENT(p));
Expand Down
2 changes: 1 addition & 1 deletion libc/str/getzipcfileoffset.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int64_t GetZipCfileOffset(const uint8_t *z) {
}
const uint8_t *p = ZIP_CFILE_EXTRA(z);
const uint8_t *pe = p + ZIP_CFILE_EXTRASIZE(z);
for (; p < pe; p += ZIP_EXTRA_SIZE(p)) {
for (; p + ZIP_EXTRA_SIZE(p) <= pe; p += ZIP_EXTRA_SIZE(p)) {
if (ZIP_EXTRA_HEADERID(p) == kZipExtraZip64) {
int offset = 0;
if (ZIP_CFILE_COMPRESSEDSIZE(z) == 0xFFFFFFFFu) {
Expand Down
2 changes: 1 addition & 1 deletion libc/str/getzipcfileuncompressedsize.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int64_t GetZipCfileUncompressedSize(const uint8_t *z) {
}
const uint8_t *p = ZIP_CFILE_EXTRA(z);
const uint8_t *pe = p + ZIP_CFILE_EXTRASIZE(z);
for (; p < pe; p += ZIP_EXTRA_SIZE(p)) {
for (; p + ZIP_EXTRA_SIZE(p) <= pe; p += ZIP_EXTRA_SIZE(p)) {
if (ZIP_EXTRA_HEADERID(p) == kZipExtraZip64) {
int offset = 0;
if (ZIP_CFILE_COMPRESSEDSIZE(z) == 0xFFFFFFFFu) {
Expand Down
2 changes: 1 addition & 1 deletion libc/str/getziplfilecompressedsize.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int64_t GetZipLfileCompressedSize(const uint8_t *z) {
}
const uint8_t *p = ZIP_LFILE_EXTRA(z);
const uint8_t *pe = p + ZIP_LFILE_EXTRASIZE(z);
for (; p < pe; p += ZIP_EXTRA_SIZE(p)) {
for (; p + ZIP_EXTRA_SIZE(p) <= pe; p += ZIP_EXTRA_SIZE(p)) {
if (ZIP_EXTRA_HEADERID(p) == kZipExtraZip64) {
if (8 <= ZIP_EXTRA_CONTENTSIZE(p)) {
return READ64LE(ZIP_EXTRA_CONTENT(p));
Expand Down
2 changes: 1 addition & 1 deletion libc/str/getziplfileuncompressedsize.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int64_t GetZipLfileUncompressedSize(const uint8_t *z) {
}
const uint8_t *p = ZIP_LFILE_EXTRA(z);
const uint8_t *pe = p + ZIP_LFILE_EXTRASIZE(z);
for (; p < pe; p += ZIP_EXTRA_SIZE(p)) {
for (; p + ZIP_EXTRA_SIZE(p) <= pe; p += ZIP_EXTRA_SIZE(p)) {
if (ZIP_EXTRA_HEADERID(p) == kZipExtraZip64) {
int offset = 0;
if (ZIP_LFILE_COMPRESSEDSIZE(z) == 0xFFFFFFFFu) {
Expand Down
2 changes: 2 additions & 0 deletions libc/zip.internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@

#define kZipCfileHdrMagic ZM_(0x02014b50) /* PK☺☻ "PK\1\2" */
#define kZipCfileHdrMinSize 46
#define kZipCfileOffsetVersionMadeBy 4
#define kZipCfileOffsetVersionNeeded 6
#define kZipCfileOffsetGeneralflag 8
#define kZipCfileOffsetCompressionmethod 10
#define kZipCfileOffsetLastmodifiedtime 12
Expand Down
14 changes: 9 additions & 5 deletions tool/build/apelink.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,9 +674,10 @@ static void LoadSymbols(Elf64_Ehdr *e, Elf64_Off size, const char *path) {
unsigned char *cfile = Malloc(cfile_size);
bzero(cfile, cfile_size);
WRITE32LE(cfile, kZipCfileHdrMagic);
cfile[4] = kZipCosmopolitanVersion;
cfile[5] = kZipOsUnix;
cfile[6] = kZipEra2001;
WRITE16LE(cfile + kZipCfileOffsetVersionMadeBy,
kZipOsUnix << 8 | kZipCosmopolitanVersion);
WRITE16LE(cfile + kZipCfileOffsetVersionNeeded, kZipEra2001);
WRITE16LE(cfile + kZipCfileOffsetGeneralflag, kZipGflagUtf8);
WRITE16LE(cfile + kZipCfileOffsetCompressionmethod, kZipCompressionDeflate);
WRITE16LE(cfile + kZipCfileOffsetLastmodifieddate, DOS_DATE(2023, 7, 29));
WRITE16LE(cfile + kZipCfileOffsetLastmodifiedtime, DOS_TIME(0, 0, 0));
Expand Down Expand Up @@ -1813,9 +1814,11 @@ int main(int argc, char *argv[]) {
int i, j;
Elf64_Off offset;
Elf64_Xword prologue_bytes;
#ifndef NDEBUG

#ifdef MODE_DBG
ShowCrashReports();
#endif

prog = argv[0];
if (!prog) prog = "apelink";

Expand Down Expand Up @@ -2080,7 +2083,8 @@ int main(int argc, char *argv[]) {
p = stpcpy(p, " count=");
loader->ddarg_size1 = p;
p = GenerateDecimalOffsetRelocation(p);
p = stpcpy(p, " bs=1 2>/dev/null | gzip -dc >\"$t.$$\" ||exit\n");
p = stpcpy(
p, " bs=1 2>/dev/null | /usr/bin/gzip -dc >\"$t.$$\" ||exit\n");
if (loader->macho_offset) {
p = stpcpy(p, "/bin/dd if=\"$t.$$\" of=\"$t.$$\"");
p = stpcpy(p, " skip=");
Expand Down
2 changes: 1 addition & 1 deletion tool/build/ar.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ int main(int argc, char *argv[]) {
struct ar_hdr header1;
struct ar_hdr header2;

#ifndef NDEBUG
#ifdef MODE_DBG
ShowCrashReports();
#endif

Expand Down
2 changes: 1 addition & 1 deletion tool/build/compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ int main(int argc, char *argv[]) {
char *s, *q, **envp;
int ws, opt, exitcode;

#ifndef NDEBUG
#ifdef MODE_DBG
ShowCrashReports();
#endif

Expand Down
2 changes: 1 addition & 1 deletion tool/build/elf2pe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ static void Pwrite(int fd, const void *data, size_t size, uint64_t offset) {
}

int main(int argc, char *argv[]) {
#ifndef NDEBUG
#ifdef MODE_DBG
ShowCrashReports();
#endif
// get program name
Expand Down
4 changes: 3 additions & 1 deletion tool/build/mkdeps.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ static const uint32_t kSourceExts[] = {
EXT("c"), // c
EXT("cc"), // c++
EXT("cpp"), // c++
EXT("cu"), // cuda
EXT("m"), // objective c
};

static char *names;
Expand Down Expand Up @@ -667,7 +669,7 @@ int main(int argc, char *argv[]) {
ssize_t rc;
size_t i, n;
char *makefile;
#ifndef NDEBUG
#ifdef MODE_DBG
ShowCrashReports();
#endif
prog = argv[0];
Expand Down
2 changes: 1 addition & 1 deletion tool/build/objbincopy.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
" INPUT is an elf executable made by the unix linker\n" \
"\n"

#ifndef NDEBUG
#ifdef MODE_DBG
#define DEBUG(...) kprintf("DEBUG: " __VA_ARGS__)
#else
#define DEBUG(...) (void)0
Expand Down
12 changes: 6 additions & 6 deletions tool/build/package.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ struct Packages {
Elf64_Xword symcount; // not persisted
int section_offset;
int section_count;
} * p;
} *p;
} objects;
struct Sections {
size_t i, n;
Expand All @@ -128,7 +128,7 @@ struct Packages {
kBss,
kOther,
} kind;
} * p;
} *p;
} sections;
struct Symbols {
size_t i, n;
Expand All @@ -139,9 +139,9 @@ struct Packages {
uint8_t type : 4;
uint16_t object; // pkg->objects.p[object]
uint16_t section; // pkg->sections.p[section]
} * p; // persisted as pkg+RVA
} *p; // persisted as pkg+RVA
} symbols, undefs; // TODO(jart): hash undefs?
} * *p; // persisted across multiple files
} **p; // persisted across multiple files
};

struct Relas {
Expand All @@ -150,7 +150,7 @@ struct Relas {
struct Rela {
const char *symbol_name;
const char *object_path;
} * p;
} *p;
} prtu;

static wontreturn void Die(const char *path, const char *reason) {
Expand Down Expand Up @@ -649,7 +649,7 @@ int main(int argc, char *argv[]) {
if (argc == 2 && !strcmp(argv[1], "-n")) {
exit(0);
}
#ifndef NDEBUG
#ifdef MODE_DBG
ShowCrashReports();
#endif
bzero(&pkg, sizeof(pkg));
Expand Down
2 changes: 1 addition & 1 deletion tool/build/pecheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ int main(int argc, char *argv[]) {
void *map;
ssize_t size;
const char *path;
#ifndef NDEBUG
#ifdef MODE_DBG
ShowCrashReports();
#endif
for (i = 1; i < argc; ++i) {
Expand Down
2 changes: 1 addition & 1 deletion tool/build/runitd.c
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ int main(int argc, char *argv[]) {
if (g_daemonize) Daemonize();
Serve();
free(g_psk);
#if IsModeDbg()
#ifdef MODE_DBG
CheckForMemoryLeaks();
CheckForFileLeaks();
#endif
Expand Down
2 changes: 1 addition & 1 deletion tool/build/zipcopy.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ static void CopyZip(void) {
}

int main(int argc, char *argv[]) {
#ifndef NDEBUG
#ifdef MODE_DBG
ShowCrashReports();
#endif
prog = argv[0];
Expand Down
Loading

0 comments on commit 0c89516

Please sign in to comment.