[DynInst_API:] cmake problem building with -pie


Date: Tue, 11 Aug 2020 22:30:10 -0400
From: Stan Cox <scox@xxxxxxxxxx>
Subject: [DynInst_API:] cmake problem building with -pie
I came across the following while building 10.2.0 on Fedora, which builds all packages with -pie

Simplified example:

 % rm CMakeCache.txt ; LDFLAGS=-pie /usr/bin/cmake .
...
-- Check size of unsigned short
-- Check size of unsigned short - failed
-- Check size of unsigned int
-- Check size of unsigned int - failed
-- Check size of unsigned long
-- Check size of unsigned long - failed
CMake Error at /usr/share/cmake/Modules/TestBigEndian.cmake:50 (message):
  no suitable type found
Call Stack (most recent call first):
  cmake/endian.cmake:3 (TEST_BIG_ENDIAN)
  cmake/shared.cmake:93 (include)
  CMakeLists.txt:34 (include)
-- Configuring incomplete, errors occurred!

Without LDFLAGS=-pie works okay
...
-- Configuring done
-- Generating done
-- Build files have been written to: ...
-- RTlib Makefile:
-- Found LATEX: /usr/bin/latex
-- Adding Unix-specific dependencies
-- Configuring done
-- Generating done
-- Build files have been written to: ...


Looking at /usr/share/cmake/Modules/TestBigEndian.cmake the problem seems to be when compiling /usr/share/cmake/Modules/TestEndianess.c.in
% gcc test.c -Wl,-pie
/usr/bin/ld: /usr/lib/gcc/x86_64-redhat-linux/10/crtbegin.o: relocation R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when making a PIE object /usr/bin/ld: /tmp/ccM6S7QV.o: relocation R_X86_64_32S against symbol `info_little' can not be used when making a PIE object; recompile with -fPIE
collect2: error: ld returned 1 exit status
typedef short cmakeint16;
const cmakeint16 info_little[] =  {0x4854, 0x5349, 0x4920, 0x2053, 0x494c, 0x5454, 0x454c, 0x4520, 0x444e, 0x4149, 0x2e4e, 0x0000};
const cmakeint16 info_big[] =     {0x5448, 0x4953, 0x2049, 0x5320, 0x4249, 0x4720, 0x454e, 0x4449, 0x414e, 0x2e2e, 0x0000};

int main(int argc, char *argv[])
{
  int require = 0;
  require += info_little[argc];
  require += info_big[argc];
  (void)argv;
  return require;
}
[← Prev in Thread] Current Thread [Next in Thread→]