Support symbol tables with arch specific name

This commit is contained in:
Justine Tunney 2023-07-29 23:50:15 -07:00
parent bd49ea1c3a
commit 801224df67
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
5 changed files with 30 additions and 19 deletions

View file

@ -34,21 +34,27 @@
__static_yoink("__get_symbol"); __static_yoink("__get_symbol");
#ifdef __x86_64__
#define SYMTAB_ARCH ".symtab.x86"
#elif defined(__aarch64__)
#define SYMTAB_ARCH ".symtab.aarch64"
#elif defined(__powerpc64__)
#define SYMTAB_ARCH ".symtab.powerpc64"
#else
#error "unsupported architecture"
#endif
static pthread_spinlock_t g_lock; static pthread_spinlock_t g_lock;
struct SymbolTable *__symtab; // for kprintf struct SymbolTable *__symtab; // for kprintf
/** static ssize_t GetZipFile(struct Zipos *zipos, const char *name) {
* Looks for `.symtab` in zip central directory. size_t i, n, c, z;
*/ z = strlen(name);
static ssize_t FindSymtabInZip(struct Zipos *zipos) {
size_t i, n, c;
c = GetZipCdirOffset(zipos->cdir); c = GetZipCdirOffset(zipos->cdir);
n = GetZipCdirRecords(zipos->cdir); n = GetZipCdirRecords(zipos->cdir);
for (i = 0; i < n; ++i, c += ZIP_CFILE_HDRSIZE(zipos->map + c)) { for (i = 0; i < n; ++i, c += ZIP_CFILE_HDRSIZE(zipos->map + c)) {
if (ZIP_CFILE_NAMESIZE(zipos->map + c) == 7 && if (ZIP_CFILE_NAMESIZE(zipos->map + c) == z &&
READ32LE(ZIP_CFILE_NAME(zipos->map + c + 0)) == READ32LE(".sym") && !memcmp(ZIP_CFILE_NAME(zipos->map + c), name, z)) {
READ16LE(ZIP_CFILE_NAME(zipos->map + c + 4)) == READ16LE("ta") &&
*ZIP_CFILE_NAME(zipos->map + c + 6) == 'b') {
return c; return c;
} }
} }
@ -63,7 +69,8 @@ static struct SymbolTable *GetSymbolTableFromZip(struct Zipos *zipos) {
size_t size, size2; size_t size, size2;
ssize_t rc, cf, lf; ssize_t rc, cf, lf;
struct SymbolTable *res = 0; struct SymbolTable *res = 0;
if ((cf = FindSymtabInZip(zipos)) != -1) { if ((cf = GetZipFile(zipos, SYMTAB_ARCH)) != -1 ||
(cf = GetZipFile(zipos, ".symtab")) != -1) {
lf = GetZipCfileOffset(zipos->map + cf); lf = GetZipCfileOffset(zipos->map + cf);
size = GetZipLfileUncompressedSize(zipos->map + lf); size = GetZipLfileUncompressedSize(zipos->map + lf);
size2 = ROUNDUP(size, FRAMESIZE); size2 = ROUNDUP(size, FRAMESIZE);

View file

@ -96,6 +96,7 @@
#define kZipCfileOffsetCrc32 16 #define kZipCfileOffsetCrc32 16
#define kZipCfileOffsetCompressedsize 20 #define kZipCfileOffsetCompressedsize 20
#define kZipCfileOffsetUncompressedsize 24 #define kZipCfileOffsetUncompressedsize 24
#define kZipCfileOffsetNamesize 28
#define kZipCfileOffsetExternalattributes 38 #define kZipCfileOffsetExternalattributes 38
#define kZipCfileOffsetOffset 42 #define kZipCfileOffsetOffset 42
@ -106,6 +107,7 @@
#define kZipLfileOffsetLastmodifiedtime 10 #define kZipLfileOffsetLastmodifiedtime 10
#define kZipLfileOffsetLastmodifieddate 12 #define kZipLfileOffsetLastmodifieddate 12
#define kZipLfileOffsetCrc32 14 #define kZipLfileOffsetCrc32 14
#define kZipLfileOffsetNamesize 26
#define kZipLfileOffsetCompressedsize 18 #define kZipLfileOffsetCompressedsize 18
#define kZipLfileOffsetUncompressedsize 22 #define kZipLfileOffsetUncompressedsize 22
@ -170,7 +172,7 @@
#define ZIP_CFILE_COMPRESSEDSIZE(P) READ32LE(P + kZipCfileOffsetCompressedsize) #define ZIP_CFILE_COMPRESSEDSIZE(P) READ32LE(P + kZipCfileOffsetCompressedsize)
#define ZIP_CFILE_UNCOMPRESSEDSIZE(P) \ #define ZIP_CFILE_UNCOMPRESSEDSIZE(P) \
READ32LE((P) + kZipCfileOffsetUncompressedsize) READ32LE((P) + kZipCfileOffsetUncompressedsize)
#define ZIP_CFILE_NAMESIZE(P) READ16LE((P) + 28) #define ZIP_CFILE_NAMESIZE(P) READ16LE((P) + kZipCfileOffsetNamesize)
#define ZIP_CFILE_EXTRASIZE(P) READ16LE((P) + 30) #define ZIP_CFILE_EXTRASIZE(P) READ16LE((P) + 30)
#define ZIP_CFILE_COMMENTSIZE(P) READ16LE((P) + 32) #define ZIP_CFILE_COMMENTSIZE(P) READ16LE((P) + 32)
#define ZIP_CFILE_DISK(P) READ16LE((P) + 34) #define ZIP_CFILE_DISK(P) READ16LE((P) + 34)
@ -203,7 +205,7 @@
READ32LE((P) + kZipLfileOffsetCompressedsize) READ32LE((P) + kZipLfileOffsetCompressedsize)
#define ZIP_LFILE_UNCOMPRESSEDSIZE(P) \ #define ZIP_LFILE_UNCOMPRESSEDSIZE(P) \
READ32LE((P) + kZipLfileOffsetUncompressedsize) READ32LE((P) + kZipLfileOffsetUncompressedsize)
#define ZIP_LFILE_NAMESIZE(P) READ16LE((P) + 26) #define ZIP_LFILE_NAMESIZE(P) READ16LE((P) + kZipLfileOffsetNamesize)
#define ZIP_LFILE_EXTRASIZE(P) READ16LE((P) + 28) #define ZIP_LFILE_EXTRASIZE(P) READ16LE((P) + 28)
#define ZIP_LFILE_NAME(P) ((const char *)((P) + 30)) #define ZIP_LFILE_NAME(P) ((const char *)((P) + 30))
#define ZIP_LFILE_EXTRA(P) ((P) + 30 + ZIP_LFILE_NAMESIZE(P)) #define ZIP_LFILE_EXTRA(P) ((P) + 30 + ZIP_LFILE_NAMESIZE(P))

View file

@ -42,7 +42,6 @@ TEST(fork, testPipes) {
int a, b; int a, b;
int ws, pid; int ws, pid;
int pipefds[2]; int pipefds[2];
alarm(5);
ASSERT_NE(-1, pipe(pipefds)); ASSERT_NE(-1, pipe(pipefds));
ASSERT_NE(-1, (pid = fork())); ASSERT_NE(-1, (pid = fork()));
if (!pid) { if (!pid) {
@ -57,11 +56,9 @@ TEST(fork, testPipes) {
EXPECT_NE(-1, close(pipefds[0])); EXPECT_NE(-1, close(pipefds[0]));
EXPECT_NE(-1, waitpid(pid, &ws, 0)); EXPECT_NE(-1, waitpid(pid, &ws, 0));
EXPECT_EQ(31337, b); EXPECT_EQ(31337, b);
alarm(0);
} }
TEST(fork, testSharedMemory) { TEST(fork, testSharedMemory) {
alarm(5);
int ws, pid; int ws, pid;
int stackvar; int stackvar;
int *sharedvar; int *sharedvar;
@ -93,7 +90,6 @@ TEST(fork, testSharedMemory) {
EXPECT_EQ(1, *privatevar); EXPECT_EQ(1, *privatevar);
EXPECT_NE(-1, munmap(sharedvar, FRAMESIZE)); EXPECT_NE(-1, munmap(sharedvar, FRAMESIZE));
EXPECT_NE(-1, munmap(privatevar, FRAMESIZE)); EXPECT_NE(-1, munmap(privatevar, FRAMESIZE));
alarm(0);
} }
static volatile bool gotsigusr1; static volatile bool gotsigusr1;
@ -140,13 +136,11 @@ TEST(fork, childToChild) {
} }
TEST(fork, preservesTlsMemory) { TEST(fork, preservesTlsMemory) {
alarm(5);
int pid; int pid;
__get_tls()->tib_errno = 31337; __get_tls()->tib_errno = 31337;
SPAWN(fork); SPAWN(fork);
ASSERT_EQ(31337, __get_tls()->tib_errno); ASSERT_EQ(31337, __get_tls()->tib_errno);
EXITS(0); EXITS(0);
alarm(0);
} }
void ForkInSerial(void) { void ForkInSerial(void) {

View file

@ -66,6 +66,10 @@
#include "libc/x/x.h" #include "libc/x/x.h"
#include "third_party/getopt/getopt.internal.h" #include "third_party/getopt/getopt.internal.h"
#ifndef NDEBUG
__static_yoink("zipos");
#endif
#define MANUAL \ #define MANUAL \
"\ "\
SYNOPSIS\n\ SYNOPSIS\n\
@ -843,6 +847,10 @@ int main(int argc, char *argv[]) {
int ws, opt, exitcode; int ws, opt, exitcode;
char *s, *p, *q, **envp; char *s, *p, *q, **envp;
#ifndef NDEBUG
ShowCrashReports();
#endif
mode = firstnonnull(getenv("MODE"), MODE); mode = firstnonnull(getenv("MODE"), MODE);
/* /*

View file

@ -47,7 +47,7 @@ static bool ShouldCompress(const char *name, size_t namesize,
static void GetDosLocalTime(int64_t utcunixts, uint16_t *out_time, static void GetDosLocalTime(int64_t utcunixts, uint16_t *out_time,
uint16_t *out_date) { uint16_t *out_date) {
struct tm tm; struct tm tm;
CHECK_NOTNULL(localtime_r(&utcunixts, &tm)); CHECK_NOTNULL(gmtime_r(&utcunixts, &tm));
*out_time = DOS_TIME(tm.tm_hour, tm.tm_min, tm.tm_sec); *out_time = DOS_TIME(tm.tm_hour, tm.tm_min, tm.tm_sec);
*out_date = DOS_DATE(tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday + 1); *out_date = DOS_DATE(tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday + 1);
} }