Created
October 17, 2023 03:28
-
-
Save selfboot/e790432ec050646ec3c307b03c6a6784 to your computer and use it in GitHub Desktop.
In the case of dynamic linking, if there are third-party dependencies in the middle without the compilation option '-fno-omit-frame-pointer', theoretically it should be the same as static linking, and the stack information will be out of order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <unistd.h> | |
#include <thread> | |
#include "dynamic_B.h" | |
void printDynamicA() { | |
std::this_thread::sleep_for(std::chrono::milliseconds(10)); | |
printDynamicB(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
void printDynamicA(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <unistd.h> | |
#include <thread> | |
void printDynamicB() { | |
std::this_thread::sleep_for(std::chrono::milliseconds(20)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
void printDynamicB(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ tree | |
. | |
├── dynamic_A | |
│ ├── dynamic_A.cpp | |
│ └── dynamic_A.h | |
├── dynamic_B | |
│ ├── dynamic_B.cpp | |
│ └── dynamic_B.h | |
├── main.cpp | |
├── Makefile | |
├── utils.cpp | |
└── utils.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <thread> | |
#include <unistd.h> | |
#include "utils.h" | |
#include "dynamic_A/dynamic_A.h" | |
void function_entry(){ | |
write(1, "Inside main function\n", 21); | |
printUtils(); | |
printDynamicA(); | |
std::this_thread::sleep_for(std::chrono::milliseconds(10)); | |
} | |
int main() { | |
while (true) { | |
function_entry(); | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: main | |
main: main.o utils.o dynamic_A/libdynamic_A.so dynamic_B/libdynamic_B.so | |
g++ -fno-omit-frame-pointer main.o utils.o -L./dynamic_A -L./dynamic_B -Wl,-rpath,./dynamic_A:./dynamic_B -ldynamic_A -ldynamic_B -o main | |
main.o: main.cpp dynamic_A/dynamic_A.h dynamic_B/dynamic_B.h | |
g++ -fno-omit-frame-pointer -I./dynamic_A -I./dynamic_B -c main.cpp | |
utils.o: utils.cpp utils.h | |
g++ -fno-omit-frame-pointer -c utils.cpp | |
dynamic_A/libdynamic_A.so: dynamic_A/dynamic_A.o | |
g++ -shared -o dynamic_A/libdynamic_A.so dynamic_A/dynamic_A.o | |
dynamic_A/dynamic_A.o: dynamic_A/dynamic_A.cpp dynamic_A/dynamic_A.h dynamic_B/dynamic_B.h | |
g++ -fno-omit-frame-pointer -fPIC -I./dynamic_B -c dynamic_A/dynamic_A.cpp -o dynamic_A/dynamic_A.o | |
dynamic_B/libdynamic_B.so: dynamic_B/dynamic_B.o | |
g++ -shared -o dynamic_B/libdynamic_B.so dynamic_B/dynamic_B.o | |
dynamic_B/dynamic_B.o: dynamic_B/dynamic_B.cpp dynamic_B/dynamic_B.h | |
g++ -fomit-frame-pointer -fPIC -c dynamic_B/dynamic_B.cpp -o dynamic_B/dynamic_B.o | |
clean: | |
rm -f *.o *.so main dynamic_A/*.o dynamic_A/*.so dynamic_B/*.o dynamic_B/*.so |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <unistd.h> | |
#include <thread> | |
void printUtils() { | |
std::this_thread::sleep_for(std::chrono::milliseconds(10)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
void printUtils(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment