Skip to content

Instantly share code, notes, and snippets.

View MaskRay's full-sized avatar
🏠
Working from home. Need food

Fangrui Song MaskRay

🏠
Working from home. Need food
View GitHub Profile
@MaskRay
MaskRay / fdpic-no-plt.md
Created February 24, 2024 02:47
FDPIC -fno-plt
void f0(void);
void f1(void);
void f2(void);
void g() { f0(); f1(); f2(); }
g:
  push    {r4, lr}
  mov     r4, r9
  bl      f(PLT)
 mov r9, r4
@MaskRay
MaskRay / fix.py
Created February 20, 2024 05:32
Script used to help fix tests for https://github.com/llvm/llvm-project/pull/81037 ("[Driver] Improve error when a compiler-rt library is not found")
#!/usr/bin/env python
import os, re, subprocess, sys
from ipdb import set_trace as bp
def main(filename):
last = 0
while 1:
p = subprocess.run(['/tmp/Rel/bin/llvm-lit', '-v', filename], capture_output=True)
if p.returncode != 1: break
lines = p.stdout.decode().split('\n')
@MaskRay
MaskRay / abis-for-mmu-less-systems
Created February 18, 2024 05:18
ABIs for MMU-less systems
## Linux binfmt loaders
`fs/Kconfig.binfmt` defines a few loaders.
* `BINFMT_ELF` defaults to y and depends on `MMU`.
* `BINFMT_ELF_FDPIC` defaults to y when `BINFMT_ELF` is not selected. A few architecture support `BINFMT_ELF_FDPIC` for NOMMU. ARM supports FDPIC even with a MMU.
* `BINFMT_FLAT` is provided for a few architectures.
`BINFMT_AOUT`, removed in 2022, had been supported for alpha/arm/x86-32.
@MaskRay
MaskRay / typescript
Last active January 26, 2024 01:02
lld's -z separate-code
% echo 'int main(){}' > a.cc
% clang -fuse-ld=lld a.cc -z separate-code
% readelf -WSl a.out
There are 30 section headers, starting at offset 0x2868:
Section Headers:
[Nr] Name Type Address Off Size ES Flg Lk Inf Al
[ 0] NULL 0000000000000000 000000 000000 00 0 0 0
[ 1] .interp PROGBITS 00000000000002a8 0002a8 00001c 00 A 0 0 1
[ 2] .note.ABI-tag NOTE 00000000000002c4 0002c4 000020 00 A 0 0 4
@MaskRay
MaskRay / riscv-tlsdesc.md
Last active January 23, 2024 09:02
RISC-V TLSDESC works! clang, lld, musl
@MaskRay
MaskRay / jump-table.sh
Created January 18, 2024 02:46
Arm Branch Target Identification/Intel CET & jump table
PATH=/tmp/Rel/bin:$PATH
cat > switch.cc <<e
#define DO A(0) A(1) A(2) A(3) A(4) A(5) A(6) A(7) A(8) A(9) A(10) A(11) A(12) A(13)
#define A(i) void bar##i();
DO
#undef A
void ext();
void foo(int i) {
switch (i) {
#define A(i) case i: bar##i(); break;
@MaskRay
MaskRay / .config
Created January 13, 2024 09:17
.config for THP experiments
#
# Automatically generated file; DO NOT EDIT.
# Linux/x86 6.7.0 Kernel Configuration
#
CONFIG_CC_VERSION_TEXT="gcc (Debian 13.2.0-5) 13.2.0"
CONFIG_CC_IS_GCC=y
CONFIG_GCC_VERSION=130200
CONFIG_CLANG_VERSION=0
CONFIG_AS_IS_GNU=y
CONFIG_AS_VERSION=24100
@MaskRay
MaskRay / asan.md
Created January 7, 2024 08:11
Notes on AddressSanitizer

AddressSanitizer (ASan) is a compiler technology that checks addressability-related memory errors with some add-on checks. It consists of two parts: compiler instrumentation and runtime library. To put it in the simplest way,

  • The compiler instruments global variables, stack frames, and heap allocations to track shadow memory.
  • The compiler instruments memory access instructions to check shadow memory.
  • In case of an error, the inserted code calls a callback (implemented in the runtime library) to report an error with a stack trace. Normally the program will exit after the error message is printed.

Clang 3.1 implemented AddressSanitizer in 2011. GCC 4.8 integrated AddressSanitizer in 2012. MSVC (starting in Visual Studio 2019 version 16.9) added /INFERASANLIBS.

@MaskRay
MaskRay / differentials-not-closed.tsv
Last active January 17, 2024 01:14
reviews.llvm.org differentials that are not "Closed"
We can't make this file beautiful and searchable because it's too large.
https://reviews.llvm.org/D1 Abandoned Test klimek
https://reviews.llvm.org/D6 Abandoned Update all diagnostic messages in DiagnosticSemaKinds.td to use the new diffing format for types. rtrieu
https://reviews.llvm.org/D7 Abandoned test dblaikie
https://reviews.llvm.org/D9 Abandoned Test for playing around with emails klimek
https://reviews.llvm.org/D10 Abandoned A new test revision for funz klimek
https://reviews.llvm.org/D11 Abandoned Let's try again klimek
https://reviews.llvm.org/D12 Abandoned And yet another test klimek
https://reviews.llvm.org/D13 Abandoned test klimek
https://reviews.llvm.org/D14 Abandoned Test test klimek
https://reviews.llvm.org/D16 Abandoned Big test klimek
@MaskRay
MaskRay / optimize-lld-elf.md
Created October 26, 2023 05:29
Optimize lld/ELF

theme: ./theme class: text-center highlighter: shiki lineNumbers: false drawings: persist: false css: unocss routerMode: hash title: Optimize lld/ELF