Skip to content

Commit e42ab84

Browse files
Fix build error on Ubuntu 16.04
Require glibc 2.27+ for `_FORTIFY_SOURCE=2`.
1 parent b246cf1 commit e42ab84

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/OpenTelemetry.AutoInstrumentation.Native/CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,16 @@ if (ISMACOS)
130130
add_compile_options(-fstack-check)
131131
elseif(ISLINUX)
132132
add_compile_options(-stdlib=libstdc++ -DLINUX -Wno-pragmas)
133-
# Enable additional hardening on Linux
134-
add_compile_options(-D_FORTIFY_SOURCE=2)
133+
# Enable additional hardening on modern versions of Linux
134+
# Require glibc 2.27+ for _FORTIFY_SOURCE=2
135+
execute_process(COMMAND ldd --version OUTPUT_VARIABLE LDD_VERSION)
136+
if (LDD_VERSION MATCHES "([0-9]+)\\.([0-9]+)")
137+
set(GLIBC_MAJOR ${CMAKE_MATCH_1})
138+
set(GLIBC_MINOR ${CMAKE_MATCH_2})
139+
if ((GLIBC_MAJOR EQUAL 2 AND GLIBC_MINOR GREATER 26) OR GLIBC_MAJOR GREATER 2)
140+
add_compile_options(-D_FORTIFY_SOURCE=2)
141+
endif()
142+
endif()
135143
if (ISAMD64 AND HAS_FCF_PROTECTION)
136144
# CET (Control-flow Enforcement Technology) for x86_64
137145
add_compile_options(-fcf-protection=full)

0 commit comments

Comments
 (0)