Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to have Ape binaries be zip's using amalgamated build files(using external build system) #214

Open
mundusnine opened this issue Jul 18, 2021 · 3 comments

Comments

@mundusnine
Copy link

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.

@mundusnine mundusnine changed the title Unable to have Ape files be zip's using amalgamated builds(using external build system) Unable to have Ape files be zip's using amalgamated build files(using external build system) Jul 18, 2021
@mundusnine mundusnine changed the title Unable to have Ape files be zip's using amalgamated build files(using external build system) Unable to have Ape binaries be zip's using amalgamated build files(using external build system) Jul 18, 2021
@ahgamut
Copy link
Collaborator

ahgamut commented Jul 30, 2021

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
  • doesn't work with -std=c99 (because of __STRICT_ANSI__?), works with -std=gnu99
  • STATIC_YOINK of __zip_start or zip_uri_support doesn't work

@mundusnine
Copy link
Author

mundusnine commented Jul 31, 2021

Ok 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. :
image

@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.

@ahgamut
Copy link
Collaborator

ahgamut commented Jul 31, 2021

Call showcrashreports() at the start of the main function?
Here's what I did:

  1. Edit above code snippet to add showcrashreports() at the start of the main function
  2. compile to obtain hello.com.dbg and hello.com (keep both in the same directory)
  3. skip adding the sample.txt to hello.com (now it will segfault at the feof() call)
  4. run hello.com. if hello.com.dbg is in the same directory, gdb starts if hello.com crashes.
  5. if hello.com.dbg is not available, gdb doesn't start, I just get a list of registers.

2021-07-31_22-23-56_1366x768

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants