From 68e02cc9a6b33983a05b066cba7ea0cec52e07ab Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Wed, 24 Apr 2024 06:34:29 -0700 Subject: [PATCH] linux before main example --- linux_before_main/build.sh | 12 ++++++++++++ linux_before_main/linux_before_main.c | 14 ++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 linux_before_main/build.sh create mode 100644 linux_before_main/linux_before_main.c diff --git a/linux_before_main/build.sh b/linux_before_main/build.sh new file mode 100644 index 0000000..9355184 --- /dev/null +++ b/linux_before_main/build.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Path setup +src=$PWD +cd .. +mkdir -p build +cd build + + +# Build +gcc -fvisibility=hidden $src/linux_before_main.c -o linux_before_main + diff --git a/linux_before_main/linux_before_main.c b/linux_before_main/linux_before_main.c new file mode 100644 index 0000000..0ca3736 --- /dev/null +++ b/linux_before_main/linux_before_main.c @@ -0,0 +1,14 @@ +// define the "before main" function +int x = 0; +__attribute__((constructor)) +static void run_before_main_func(void){ + x = 100; +} + + +// main +#include +int main(){ + printf("x = %d\n", x); + return(0); +} \ No newline at end of file