Skip to content

Instantly share code, notes, and snippets.

Niklas Hambüchen nh2

Block or report user

Report or block nh2

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
nh2 /
Created Dec 16, 2018
How autoconf does some feature detection on cross compilation

Originally from #ghc on freenode, 2018-12-16:

Most of the checks seem to actually be no-ops for cross-compilation. E.g. checking for working strnlen is just hardcoded to "yes" on all targets but AIX (in similar other cases, it just prints "guessing yes").

For checking size of int *, it does a binary search as you say, and NOT invoke the compiled programs. It does it by generating a static array with known size, like arr[1 - 2 * (sizeof(int*) <= BINARY_SEARCH_VAR)], so that the static size is either [1] or [-1]. C compilers happen to complain about arrays of negative static size, so that's how it figures that out. See ac_fn_c_compute_int().

To see this, I use for compilation of GNU hello, the following added to

nh2 / add-bluetoothd-flag.nix
Created Dec 9, 2018
Shows how to add `-P` to bluetoothd in NixOS
View add-bluetoothd-flag.nix
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "bluez-patched-systemd-unit";
buildCommand = let
in ''
set -eo pipefail
cp -rvs ${pkgs.bluez} --no-preserve=mode $out
sed --in-place 's:bluetooth/bluetoothd:bluetooth/bluetoothd -P:g' $out/etc/systemd/system/bluetooth.service
nh2 / dmesg.txt
Last active Dec 3, 2018
dmesg output showing failure of 2 devices in RAID1
View dmesg.txt
$ dmesg
[ 0.000000] microcode: CPU0 microcode updated early to revision 0x1f, date = 2018-02-07
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Initializing cgroup subsys cpuacct
[ 0.000000] Linux version 4.4.0-131-generic (buildd@lgw01-amd64-015) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.10) ) #157-Ubuntu SMP Thu Jul 12 15:51:36 UTC 2018 (Ubuntu 4.4.0-131.157-generic 4.4.134)
[ 0.000000] Command line: BOOT_IMAGE=/vmlinuz-4.4.0-131-generic root=/dev/mapper/vg0-ubuntu1604 ro console=tty1 console=ttyS0,115200
[ 0.000000] KERNEL supported cpus:
[ 0.000000] Intel GenuineIntel
[ 0.000000] AMD AuthenticAMD
nh2 / Setup.hs
Last active Dec 1, 2018
Haskell: Patching libc with Cabal postBuild hook
View Setup.hs
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -Wall #-}
import Control.Concurrent.Async (forConcurrently_)
import Data.Foldable (for_)
import Data.List (intercalate)
import qualified Data.Map as Map
import Data.Semigroup ((<>))
import qualified Data.Text as T
nh2 / gdb-stracktrace.txt
Created Nov 28, 2018
Crazy sched_yield() spam in GHC-compiled program that is quite idle but takes high CPU usage
View gdb-stracktrace.txt
#0 0x00007f5b1ebe458f in pthread_cond_wait@@GLIBC_2.3.2 () from /nix/store/hwwqshlmazzjzj7yhrkyjydxamvvkfd3-glibc-2.26-131/lib/
#1 0x0000000001d06f69 in waitCondition ()
#2 0x0000000001cf533b in yieldCapability ()
#3 0x0000000001cf26c9 in schedule ()
#4 0x0000000001cf37ac in scheduleWorker ()
#5 0x00007f5b1ebde2a7 in start_thread () from /nix/store/hwwqshlmazzjzj7yhrkyjydxamvvkfd3-glibc-2.26-131/lib/
#6 0x00007f5b002a757f in clone () from /nix/store/hwwqshlmazzjzj7yhrkyjydxamvvkfd3-glibc-2.26-131/lib/
nh2 / ghc_1.s
Created Nov 26, 2018
Investigation of Cabal c-sources not yielding debugging symbols
View ghc_1.s
.file "lz4frame.c"
.section .text.unlikely,"ax",@progbits
.p2align 4,,15
.section .text.unlikely
nh2 / ghc-g-to-as.txt
Last active Nov 26, 2018
Passing -g to as via GHC
View ghc-g-to-as.txt
Using ghc-8.2.2
-g -optc-g -opta-g -optc-Wa,-g -opta-Wa,-g
passes -g to as
-g -optc-g -opta-g -optc-Wa,-g
does not pass -g to as
-g -optc-g -opta-g -opta-Wa,-g
passes -g to as
#!/usr/bin/env python3
import argparse
import copy
import json
import sys
def migrate(input_dict):
j = copy.deepcopy(input_dict)
nh2 / CompactTest.hs
Created Oct 7, 2018
Example on how to use Compact values for serialisation with GHC
View CompactTest.hs
#!/usr/bin/env stack
-- stack --resolver lts-11.22 script --optimize
{-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Data.Compact (compact, getCompact)
import Data.Compact.Serialize (writeCompact, unsafeReadCompact)
import System.Environment (getArgs)
nh2 / TraverseMaybePerformance.hs
Last active Oct 7, 2018
Memory leak in for_, traverse_ and forM_ for Maybe and many other types. Test case for
View TraverseMaybePerformance.hs
#!/usr/bin/env stack
-- stack --resolver lts-11.22 script --optimize
-- The problem:
-- traverse_ / forM_ / for_ leak memory for `Maybe`.
-- There are a couple background posts about it:
-- 2014-05 Yesodweb:
-- 2014-05 School of Haskell:
-- 2017-01
You can’t perform that action at this time.