linux before main example
							parent
							
								
									81ab0a3bbd
								
							
						
					
					
						commit
						68e02cc9a6
					
				|  | @ -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 | ||||
| 
 | ||||
|  | @ -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); | ||||
| } | ||||
		Loading…
	
		Reference in New Issue