linux before main example

main
Allen Webster 2024-04-24 06:34:29 -07:00
parent 81ab0a3bbd
commit 68e02cc9a6
2 changed files with 26 additions and 0 deletions

View File

@ -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

View File

@ -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 <stdio.h>
int main(){
printf("x = %d\n", x);
return(0);
}