aom_configure.cmake: detect PIE and set CONFIG_PIC
Fixes the creation of DT_TEXTREL entries in binaries built with PIE
enabled:
/usr/bin/ld: warning: creating DT_TEXTREL in a PIE
Bug: b/229626362
Change-Id: I37a0eaf6b7471953d2c8b3f7f903c84cb2acbd2d
(cherry picked from commit 7235e6574663af3d93786f72261a0b2be91e453d)
diff --git a/build/cmake/aom_configure.cmake b/build/cmake/aom_configure.cmake
index 27b94a9..1a8bae5 100644
--- a/build/cmake/aom_configure.cmake
+++ b/build/cmake/aom_configure.cmake
@@ -110,6 +110,21 @@
if(BUILD_SHARED_LIBS)
set(CONFIG_PIC 1)
set(CONFIG_SHARED 1)
+elseif(NOT CONFIG_PIC)
+ aom_check_c_compiles("pie_check" "
+ #if !(__pie__ || __PIE__)
+ #error Neither __pie__ or __PIE__ are set
+ #endif
+ extern void unused(void);
+ void unused(void) {}" HAVE_PIE)
+
+ if(HAVE_PIE)
+ # If -fpie or -fPIE are used ensure the assembly code has PIC enabled to
+ # avoid DT_TEXTRELs: /usr/bin/ld: warning: creating DT_TEXTREL in a PIE
+ set(CONFIG_PIC 1)
+ message(
+ "CONFIG_PIC enabled for position independent executable (PIE) build")
+ endif()
endif()
if(NOT MSVC)