Skip to content

Commit 20ca1bd

Browse files
committed
add golang static build option
1 parent 3a4ecef commit 20ca1bd

3 files changed

Lines changed: 8 additions & 11 deletions

File tree

rasp/Makefile

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,8 @@ python: python-probe ## build CPython probe
130130

131131

132132
go-probe: ## build golang probe
133-
ifeq ($(STATIC), TRUE)
134-
mkdir -p golang/build && cd golang/build && \
135-
CC=$(CC) CXX=$(CXX) CFLAGS="-static-pie" CXXFLAGS=-static-pie cmake .. && make
136-
else
137133
mkdir -p golang/build && cd golang/build && \
138-
CC=$(CC) CXX=$(CXX) cmake .. && make
139-
endif
134+
CC=$(CC) CXX=$(CXX) cmake -DSTATIC_BUILD=$(STATIC) .. && make
140135

141136

142137
go: go-probe ## build go probe

rasp/golang/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ set(CMAKE_CXX_STANDARD 14)
66
include_directories(include)
77
include_directories(${CMAKE_SOURCE_DIR})
88

9+
option(STATIC_BUILD "enable static build" OFF)
10+
911
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
1012
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
1113

@@ -44,6 +46,6 @@ add_executable(go_probe main.cpp asm/inline_hook.cpp asm/api_hook.cpp futex/mute
4446
go/symbol/line_table.cpp go/symbol/func.cpp go/registry/api_registry.cpp
4547
go/api/workspace.cpp go/api/api.cpp go/stack/printf/printf.c)
4648

47-
target_link_libraries(go_probe elfio Zydis nlohmann_json event_core_static event_pthreads_static)
48-
target_link_libraries(go_loader elfio Zydis nlohmann_json event_core_static event_pthreads_static)
49-
target_link_libraries(go_sample elfio Zydis nlohmann_json event_core_static event_pthreads_static ${CMAKE_DL_LIBS})
49+
target_link_libraries(go_sample elfio Zydis nlohmann_json event_core_static event_pthreads_static ${CMAKE_DL_LIBS})
50+
target_link_libraries(go_loader elfio Zydis nlohmann_json event_core_static event_pthreads_static $<$<BOOL:${STATIC_BUILD}>:-static-pie>)
51+
target_link_libraries(go_probe elfio Zydis nlohmann_json event_core_static event_pthreads_static $<$<BOOL:${STATIC_BUILD}>:-static-pie>)

rasp/golang/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<!-- PROJECT LOGO -->
2-
<br />
32
<p align="center">
43
<h3 align="center">go-probe</h3>
54

@@ -147,4 +146,5 @@ Project Link: [https://github.com/bytedance/Elkeid](https://github.com/bytedance
147146
* [zydis](https://github.com/zyantific/zydis)
148147
* [libevent](https://github.com/libevent/libevent)
149148
* [ELFIO](https://github.com/serge1/ELFIO)
150-
* [json](https://github.com/nlohmann/json)
149+
* [json](https://github.com/nlohmann/json)
150+
* [printf](https://github.com/mpaland/printf)

0 commit comments

Comments
 (0)