Skip to content

Instantly share code, notes, and snippets.

@scottt
scottt / libc.so.json
Created August 26, 2017 22:37
dwarf-analyze-gcc-swithces output
{
"Assembler" : {
"GNU AS 2.27" : [
"/usr/src/debug/glibc-2.25-24-g49f97e6/elf/../sysdeps/x86_64/dl-trampoline.h",
"/usr/src/debug/glibc-2.25-24-g49f97e6/elf/../sysdeps/x86_64/dl-tlsdesc.S",
"/usr/src/debug/glibc-2.25-24-g49f97e6/elf/../sysdeps/x86_64/tls_get_addr.S",
"/usr/src/debug/glibc-2.25-24-g49f97e6/io/../sysdeps/unix/syscall-template.S",
"/usr/src/debug/glibc-2.25-24-g49f97e6/io/../sysdeps/unix/syscall-template.S",
"/usr/src/debug/glibc-2.25-24-g49f97e6/io/../sysdeps/unix/syscall-template.S",
"/usr/src/debug/glibc-2.25-24-g49f97e6/io/../sysdeps/unix/syscall-template.S",
/* Includes */
#include <unistd.h> /* Symbolic Constants */
#include <sys/types.h> /* Primitive System Data Types */
#include <errno.h> /* Errors */
#include <stdio.h> /* Input/Output */
#include <stdlib.h> /* General Utilities */
#include <pthread.h> /* POSIX Threads */
#include <string.h> /* String handling */
/* prototype for thread routine */
#include <unistd.h>
#include <assert.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
char *c;
sigjmp_buf jbuf;
#ifndef __x86_64__
#error "This code only works on x86-64."
#endif
#define _GNU_SOURCE
#include <unistd.h>
#include <assert.h>
#ifndef __x86_64__
#error "This code only works on x86-64."
#endif
@scottt
scottt / iterate-linked-list.c
Last active September 19, 2016 01:30
Explaining the Data Dependency Issue Exposed in "A cache miss is not a cache miss"
struct pair { int first, int second };
/* LOAD() is just a pointer dereference. Written this way to make it stand out. */
#define LOAD(expr) (*(expr))
void iterate_linked_list(vector)
{
register void *vector_start = vector->start;
register long index = 0;
register long sum = 0;
@scottt
scottt / dyld.log
Last active May 4, 2016 15:02
Self-contained Qt app bundles on OSX
dyld: loaded: /Users/user/work/chicken-bibi/chicken-bibi/./bibi.app/Contents/MacOS/bibi
dyld: loaded: /Users/user/work/chicken-bibi/chicken-bibi/bibi.app/Contents/MacOS/../Frameworks/QtWidgets.framework/Versions/5/QtWidgets
dyld: loaded: /Users/user/work/chicken-bibi/chicken-bibi/bibi.app/Contents/MacOS/../Frameworks/QtGui.framework/Versions/5/QtGui
dyld: loaded: /Users/user/work/chicken-bibi/chicken-bibi/bibi.app/Contents/MacOS/../Frameworks/QtCore.framework/Versions/5/QtCore
dyld: loaded: /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL
dyld: loaded: /System/Library/Frameworks/AGL.framework/Versions/A/AGL
dyld: loaded: /usr/lib/libc++.1.dylib
dyld: loaded: /usr/lib/libSystem.B.dylib
dyld: loaded: /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon
dyld: loaded: /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa
@scottt
scottt / bin-true-ld.so-processing-log
Last active April 6, 2021 06:17
Observe mmap operations performed by the dynamic linker by running "gdb -x observe-maps-on-mmap.py"
== malloc()
_dl_init_paths()
Catchpoint 1 (syscalls 'mmap' [9] 'mprotect' [10] 'munmap' [11])
Breakpoint 2 at 0x1650: file src/true.c, line 59.
Catchpoint 1 (call to syscall mmap), 0x00007ffff7df54da in mmap64 () at ../sysdeps/unix/syscall-template.S:84
84 T_PSEUDO (SYSCALL_SYMBOL, SYSCALL_NAME, SYSCALL_NARGS)
Catchpoint 1 (returned from syscall mmap), 0x00007ffff7df54da in mmap64 () at ../sysdeps/unix/syscall-template.S:84
@scottt
scottt / plt.gdb
Last active February 3, 2016 19:19
file s
set disable-randomization on
set disassemble-next-line on
# break on call 'swap@plt' in main
break *0x0804857c
break 'swap@plt'
run
si
disassemble 'swap@plt'
printf "\n\ninfo symbol 0x804a014: "
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@scottt
scottt / matplotlib-artist-object-api.ipynb
Last active November 25, 2015 05:48
Matplotlib Artist Object API
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.