Skip to content

Instantly share code, notes, and snippets.

Andrew Kelley andrewrk

Block or report user

Report or block andrewrk

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@andrewrk
andrewrk / build-commands.txt
Created Jul 12, 2019
troubleshooting segfault with cross compiled windows binaries that link libc
View build-commands.txt
[nix-shell:~/downloads/zig/build]$ ./zig build-exe --c-source hello.c -target x86_64-windows-gnu --library c --verbose-cc --verbose-link
/home/andy/downloads/zig/build/zig cc -MD -MV -MF zig-cache/tmp/RYvsWTfvvK2C-hello.obj.d -nostdinc -fno-spell-checking -isystem /home/andy/downloads/zig/build/lib/zig/include -isystem /home/andy/downloads/zig/build/lib/zig/libc/include/x86_64-windows-gnu -isystem /home/andy/downloads/zig/build/lib/zig/libc/include/generic-mingw -isystem /home/andy/downloads/zig/build/lib/zig/libc/include/x86_64-windows-any -isystem /home/andy/downloads/zig/build/lib/zig/libc/include/any-windows-any -target x86_64-unknown-windows-gnu -Wno-pragma-pack -g -D_DEBUG -fstack-protector-strong --param ssp-buffer-size=4 -fno-omit-frame-pointer -o zig-cache/tmp/RYvsWTfvvK2C-hello.obj -c hello.c
/home/andy/downloads/zig/build/zig cc -MD -MV -MF /home/andy/.local/share/zig/stage1/tmp/HjzIZ8o3Jv1I-crtexe.obj.d -nostdinc -fno-spell-checking -isystem /home/andy/downloads/zig/build/lib/zig/include -target
@andrewrk
andrewrk / c.ll
Last active Jul 8, 2019
clang-8 -c c.ll -O3 -target wasm32-unknown-musl
View c.ll
; ModuleID = 'c'
source_filename = "c"
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
target triple = "wasm32-unknown-unknown-musl"
%"[]u8.0" = type { i8*, i32 }
%builtin.StackTrace.1 = type { i32, %"[]usize.2" }
%"[]usize.2" = type { i32*, i32 }
%"std.math.frexp.frexp_result(f64)" = type { double, i32 }
%std.math.fma.dd = type { double, double }
@andrewrk
andrewrk / 0test.zig
Created Jun 8, 2019
result location demo
View 0test.zig
export fn entry() void {
const static = Foo{
.x = 9,
.bar = Bar{ .y = 10 },
};
const runtime = foo(true);
}
fn foo(c: bool) Foo {
return Foo{
@andrewrk
andrewrk / errno.h
Last active May 27, 2019
windows ucrt libc errno.h
View errno.h
//
// errno.h
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// System error numbers for use with errno and errno_t.
//
#pragma once
#ifndef _INC_ERRNO // include guard for 3rd party interop
#define _INC_ERRNO
@andrewrk
andrewrk / 1-brute-force.c
Created May 1, 2019
cleanup code techniques
View 1-brute-force.c
int main(int argc, char **argv) {
struct SoundIo *soundio = soundio_create();
if (!soundio) {
fprintf(stderr, "out of memory\n");
return 1;
}
int err;
if ((err = soundio_connect(soundio))) {
fprintf(stderr, "unable to connect: %s\n", soundio_strerror(err));
soundio_destroy(soundio);
@andrewrk
andrewrk / debug.zig
Created Apr 11, 2019
demo of using Zig's standard library from C code
View debug.zig
const std = @import("std");
const builtin = @import("builtin");
export fn captureStackTrace(addresses: [*]usize, len: usize, first_addr: usize) void {
var trace = builtin.StackTrace{
.instruction_addresses = addresses[0..len],
.index = 0,
};
std.debug.captureStackTrace(if (first_addr == 0) null else first_addr, &trace);
}
@andrewrk
andrewrk / libc.txt
Created Apr 8, 2019
example of `zig libc` on windows
View libc.txt
c:\msys64\home\andy\dev\zig\build-release-llvm8>bin\zig.exe libc
# The directory that contains `stdlib.h`.
# On POSIX-like systems, include directories be found with: `cc -E -Wp,-v -xc /dev/null`
include_dir=C:\Program Files (x86)\Windows Kits\10\\Include\10.0.17134.0\ucrt
# The system-specific include directory. May be the same as `include_dir`.
# On Windows it's the directory that includes `vcruntime.h`.
# On POSIX it's the directory that includes `sys/errno.h`.
sys_include_dir=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.15.26726\lib\x64\\..\..\include
# The directory that contains `crt1.o`.
@andrewrk
andrewrk / git.txt
Created Mar 13, 2019
files in linux headers that have same names with different casing
View git.txt
modified: libc/include/generic-musl/linux/netfilter/xt_CONNMARK.h
modified: libc/include/generic-musl/linux/netfilter/xt_DSCP.h
modified: libc/include/generic-musl/linux/netfilter/xt_MARK.h
modified: libc/include/generic-musl/linux/netfilter/xt_RATEEST.h
modified: libc/include/generic-musl/linux/netfilter/xt_TCPMSS.h
modified: libc/include/generic-musl/linux/netfilter_ipv4/ipt_ECN.h
modified: libc/include/generic-musl/linux/netfilter_ipv4/ipt_TTL.h
modified: libc/include/generic-musl/linux/netfilter_ipv6/ip6t_HL.h
@andrewrk
andrewrk / multibuild.zig
Created Mar 6, 2019
using zig instead of bash template
View multibuild.zig
const std = @import("std");
const os = std.os;
const src = "/home/andy/downloads/glibc";
const j_arg = "-j2";
const configure = src ++ "/configure";
const Target = struct {
glibc_name: []const u8,
@andrewrk
andrewrk / cmds.txt
Last active Mar 4, 2019
how to build glibc 2.29 startup files
View cmds.txt
start.os: gcc ../sysdeps/x86_64/start.S -c -I../include -I/home/andy/downloads/glibc/build/csu -I/home/andy/downloads/glibc/build -I../sysdeps/unix/sysv/linux/x86_64/64 -I../sysdeps/unix/sysv/linux/x86_64 -I../sysdeps/unix/sysv/linux/x86/include -I../sysdeps/unix/sysv/linux/x86 -I../sysdeps/x86/nptl -I../sysdeps/unix/sysv/linux/wordsize-64 -I../sysdeps/x86_64/nptl -I../sysdeps/unix/sysv/linux/include -I../sysdeps/unix/sysv/linux -I../sysdeps/nptl -I../sysdeps/pthread -I../sysdeps/gnu -I../sysdeps/unix/inet -I../sysdeps/unix/sysv -I../sysdeps/unix/x86_64 -I../sysdeps/unix -I../sysdeps/posix -I../sysdeps/x86_64/64 -I../sysdeps/x86_64/fpu/multiarch -I../sysdeps/x86_64/fpu -I../sysdeps/x86/fpu/include -I../sysdeps/x86/fpu -I../sysdeps/x86_64/multiarch -I../sysdeps/x86_64 -I../sysdeps/x86 -I../sysdeps/ieee754/float128 -I../sysdeps/ieee754/ldbl-96/include -I../sysdeps/ieee754/ldbl-96 -I../sysdeps/ieee754/dbl-64/wordsize-64 -I../sysdeps/ieee754/dbl-64 -I../sysdeps/ieee754/flt-32 -I..
You can’t perform that action at this time.