Add support for symbol table in .com files

This change fixes minor bugs and adds a feature, which lets us store the
ELF symbol table, inside the ZIP directory. We use the path /zip/.symtab
which can be safely removed using a zip editing tool, to make the binary
smaller after compilation. This supplements the existing method of using
a separate .com.dbg file, which is still supported. The intent is people
don't always know that it's a good idea to download the debug file. It's
not great having someone's first experience be a crash report, that only
has numbers rather than symbols. This will help fix that!
This commit is contained in:
Justine Tunney 2022-03-23 06:31:55 -07:00
parent 393ca4be40
commit 23b72eb617
61 changed files with 963 additions and 510 deletions

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/internal.h"
#include "libc/calls/strace.internal.h"
#include "libc/dce.h"
#include "libc/sock/internal.h"
#include "libc/sock/sock.h"
@ -34,14 +35,20 @@
*/
int getsockopt(int fd, int level, int optname, void *out_opt_optval,
uint32_t *out_optlen) {
if (!level || !optname) return enoprotoopt(); /* our sysvconsts definition */
if (optname == -1) return 0; /* our sysvconsts definition */
if (!IsWindows()) {
return sys_getsockopt(fd, level, optname, out_opt_optval, out_optlen);
int rc;
if (!level || !optname) {
rc = enoprotoopt(); /* our sysvconsts definition */
} else if (optname == -1) {
rc = 0; /* our sysvconsts definition */
} else if (!IsWindows()) {
rc = sys_getsockopt(fd, level, optname, out_opt_optval, out_optlen);
} else if (__isfdkind(fd, kFdSocket)) {
return sys_getsockopt_nt(&g_fds.p[fd], level, optname, out_opt_optval,
out_optlen);
rc = sys_getsockopt_nt(&g_fds.p[fd], level, optname, out_opt_optval,
out_optlen);
} else {
return ebadf();
rc = ebadf();
}
STRACE("getsockopt(%d, %#x, %#x, %p, %p) → %d% m", fd, level, optname,
out_opt_optval, out_optlen, rc);
return rc;
}

View file

@ -17,6 +17,7 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/internal.h"
#include "libc/calls/strace.internal.h"
#include "libc/dce.h"
#include "libc/errno.h"
#include "libc/nt/winsock.h"
@ -50,19 +51,29 @@ static bool setsockopt_polyfill(int *optname) {
*/
int setsockopt(int fd, int level, int optname, const void *optval,
uint32_t optlen) {
if (!optval) return efault();
if (!level || !optname) return enoprotoopt(); /* our sysvconsts definition */
if (optname == -1) return 0; /* our sysvconsts definition */
if (!IsWindows()) {
int e, rc;
if (!optval) {
rc = efault();
} else if (!level || !optname) {
rc = enoprotoopt(); /* our sysvconsts definition */
} else if (optname == -1) {
rc = 0; /* our sysvconsts definition */
} else if (!IsWindows()) {
rc = -1;
e = errno;
do {
if (sys_setsockopt(fd, level, optname, optval, optlen) != -1) {
return 0;
errno = e;
rc = 0;
break;
}
} while (setsockopt_polyfill(&optname));
return -1;
} else if (__isfdkind(fd, kFdSocket)) {
return sys_setsockopt_nt(&g_fds.p[fd], level, optname, optval, optlen);
rc = sys_setsockopt_nt(&g_fds.p[fd], level, optname, optval, optlen);
} else {
return ebadf();
rc = ebadf();
}
STRACE("setsockopt(%d, %#x, %#x, %p, %'u) → %d% m", fd, level, optname,
optval, optlen, rc);
return rc;
}

View file

@ -46,7 +46,7 @@ int socket(int family, int type, int protocol) {
} else {
rc = sys_socket_nt(family, type, protocol);
}
STRACE("socket(%s, %s, %s) -> %d% m", __describe_socket_family(family),
STRACE("socket(%s, %s, %s) %d% m", __describe_socket_family(family),
__describe_socket_type(type), __describe_socket_protocol(protocol),
rc);
return rc;