Skip to content

Instantly share code, notes, and snippets.

@rprichard
rprichard / realpath.c
Created December 19, 2019 22:04
realpath test with deleted file: "A (deleted)"
#include <assert.h>
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
int main() {
@rprichard
rprichard / ASAN DSOs
Created September 26, 2019 22:57
ASAN prebuilts and STL dependencies
$ for x in prebuilts/clang/host/linux-x86/clang-r365631b/lib64/clang/9.0.7/lib/linux/libclang_rt.asan-*.so; do printf "\n$x\n\n"; readelf -d $x | grep 'RUNPATH\|c++'; readelf -s -W $x | c++filt | grep ' __dynamic_cast\|typeinfo for std::type_info'; done
prebuilts/clang/host/linux-x86/clang-r365631b/lib64/clang/9.0.7/lib/linux/libclang_rt.asan-aarch64-android.so
4833: 00000000000b25b8 16 OBJECT LOCAL DEFAULT 17 typeinfo for std::type_info
4878: 00000000000acb28 536 FUNC LOCAL DEFAULT 14 __dynamic_cast
prebuilts/clang/host/linux-x86/clang-r365631b/lib64/clang/9.0.7/lib/linux/libclang_rt.asan-arm-android.so
0x00000001 NEEDED Shared library: [libc++.so]
@rprichard
rprichard / build.sh
Created July 30, 2019 20:33
Demonstrate misalignment when (p_vaddr % p_align) != 0
#!/bin/bash
CLANG=/x/llvm-upstream/stage1/bin/clang
$CLANG -target aarch64-linux-gnu -fpic -shared libtls.c -fuse-ld=lld -o libtls.so
$CLANG -target aarch64-linux-gnu main.c -ldl -o main -Wl,-rpath,'$ORIGIN'
@rprichard
rprichard / benchmark_output.txt
Created July 25, 2019 01:05
__thread vs thread_local
rprichard@cashew:/x/bionic-dev$ out/host/linux-x86/benchmarktest64/bionic-benchmarks-glibc/bionic-benchmarks-glibc --benchmark_filter='BM_tls'
Failed to raise priority of process. Are you root?
: Permission denied
2019-07-24 17:49:56
Running out/host/linux-x86/benchmarktest64/bionic-benchmarks-glibc/bionic-benchmarks-glibc
Run on (56 X 3500 MHz CPU s)
CPU Caches:
L1 Data 32K (x28)
L1 Instruction 32K (x28)
L2 Unified 256K (x28)
@rprichard
rprichard / CMake build.ninja
Created March 11, 2019 10:41
Comparison of edge statement for AArch64ISelLowering.cpp
build lib/Target/AArch64/CMakeFiles/LLVMAArch64CodeGen.dir/AArch64ISelLowering.cpp.o: CXX_COMPILER__LLVMAArch64CodeGen /x/llvm-upstream/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp || cmake_object_order_depends_target_LLVMAArch64CodeGen
DEFINES = -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
DEP_FILE = lib/Target/AArch64/CMakeFiles/LLVMAArch64CodeGen.dir/AArch64ISelLowering.cpp.o.d
FLAGS = -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -UNDEBUG -fno-exceptions -fno-rtti
INCLUDES = -Ilib/Target/AArch64 -I/x/llvm-upstream/llvm/lib/Target/AArch64 -Iinclude -I/x/llvm-upstream/llv
#!/bin/bash
set -e
cat >test.h <<EOF
struct A {
virtual void key();
};
struct B : A {
virtual void key();
};
EOF
@rprichard
rprichard / emutls-dtor-problem.cpp
Created May 9, 2018 21:52
Demonstrate emutls + thread_local dtor bug
// Copyright 2018 Google LLC.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@rprichard
rprichard / nftw-test.c
Last active May 10, 2018 04:31
nftw test
// Copyright 2018 Google LLC.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
#!/usr/bin/env python
class Node(object):
"""A node in a directed graph."""
def __init__(self, name, outs):
"""Initializes a Node.
Args:
name: The name of this node.
# Copyright (C) 2018 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,