Skip to content

Instantly share code, notes, and snippets.

Created October 17, 2023 03:28
Show Gist options
  • Save selfboot/e790432ec050646ec3c307b03c6a6784 to your computer and use it in GitHub Desktop.
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
#include <unistd.h>
#include <thread>
#include "dynamic_B.h"
void printDynamicA() {
#pragma once
void printDynamicA();
#include <unistd.h>
#include <thread>
void printDynamicB() {
#pragma once
void printDynamicB();
$ tree
├── dynamic_A
│   ├── dynamic_A.cpp
│   └── dynamic_A.h
├── dynamic_B
│   ├── dynamic_B.cpp
│   └── dynamic_B.h
├── main.cpp
├── Makefile
├── utils.cpp
└── utils.h
#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);
int main() {
while (true) {
return 0;
all: main
main: main.o utils.o dynamic_A/ dynamic_B/
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/ dynamic_A/dynamic_A.o
g++ -shared -o dynamic_A/ 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/ dynamic_B/dynamic_B.o
g++ -shared -o dynamic_B/ 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
rm -f *.o *.so main dynamic_A/*.o dynamic_A/*.so dynamic_B/*.o dynamic_B/*.so
#include <unistd.h>
#include <thread>
void printUtils() {
#pragma once
void printUtils();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment