Skip to content

Instantly share code, notes, and snippets.

@wader
Created March 13, 2025 11:51
Show Gist options
  • Save wader/b29144b9ce191913028d53cc39faade3 to your computer and use it in GitHub Desktop.
Save wader/b29144b9ce191913028d53cc39faade3 to your computer and use it in GitHub Desktop.
alpine rust local key crash (failed reproduction)
# docker build --platform linux/amd64 --progress=plain .
FROM alpine:3.21.0
RUN apk add --no-cache \
coreutils \
rust cargo cargo-c \
bash \
build-base
COPY test.rs .
COPY test.c .
RUN rustc -C target-feature=+crt-static --crate-type=staticlib test.rs
RUN gcc -O3 -static-libgcc -fno-strict-overflow -fstack-protector-all -fPIC -c test.c
RUN gcc -Wl,-z,relro,-z,now -o test test.o -L . -ltest -fPIE -static-pie
RUN file test
RUN ./test
#include <stdio.h>
#include <inttypes.h>
uint64_t random_state(uint64_t value);
int main()
{
uint64_t r = random_state(123);
printf("r=%" PRIu64 "\n", r);
return 0;
}
use std::hash::{BuildHasher, RandomState};
#[unsafe(no_mangle)]
pub extern "C" fn random_state(value: u64) -> u64 {
RandomState::new().hash_one(value)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment