Open mundusnine opened 3 years ago
Can you provide a minimal example? The below example works:
hello.c:
#include <stdio.h>
#include <time.h>
#ifdef COSMOPOLITAN_H_
STATIC_YOINK("usr/share/zoneinfo/Beijing");
// yoinking __zip_start or zip_uri_support doesn't work
#endif
int main(int argc, char **argv) {
#ifdef COSMOPOLITAN_H_
showcrashreports();
FILE *f = fopen("zip:sample.txt", "r");
char buf[128];
if(feof(f)) return 1;
printf("viewing file:\n");
while(fgets(buf, sizeof(buf), f) != NULL)
printf("%s\n", buf);
fclose(f);
#endif
return 0;
}
Compilation:
gcc hello.c -std=gnu99 -g3 -Og \
-static -nostdlib -nostdinc -fno-pie \
-mno-red-zone -fno-omit-frame-pointer \
-pg -no-pie \
-I../libcosmo/header_stubs/ \
-o hello.com.dbg \
-fuse-ld=bfd \
-Wl,-T,../libcosmo/ape.lds \
-include ../libcosmo/cosmopolitan.h ../libcosmo/crt.o ../libcosmo/ape.o ../libcosmo/cosmopolitan.a
objcopy --strip-all --output-target binary hello.com.dbg hello.com
echo "cosmopolitan libc" > sample.txt
zip hello.com sample.txt
unzip -l hello.com
./hello.com
-std=c99
(because of __STRICT_ANSI__
?), works with -std=gnu99
STATIC_YOINK
of __zip_start
or zip_uri_support
doesn't workOk so by using the commands you used I was able to make the .com file a zip but only when the .com file was stripped of all debug information. i.e. :
@jart is it desired that when the .com file is a .com.dbg that we can't use it as a zip ? If so how would one debug code that uses fopen("zip:sample.txt","r")
? In the image I supplied the first time I do zip hello.com sample.txt
the hello.com file is actually a .com.dbg
file.
Call showcrashreports()
at the start of the main
function?
Here's what I did:
showcrashreports()
at the start of the main
functionhello.com.dbg
and hello.com
(keep both in the same directory)hello.com
(now it will segfault at the feof()
call)hello.com
. if hello.com.dbg
is in the same directory, gdb
starts if hello.com
crashes.hello.com.dbg
is not available, gdb
doesn't start, I just get a list of registers.
I am trying to build ape files as archives to store application data using the amalgamated files supplied for the build.
I tried doing what was outlined here: #166 but no cigar.
I am able to build the ape files using the commands shown here but they don't have the PK begin and end signatures.
Building on Debian 10 with default gcc.