Merge pull request #13 from eternalharvest/feature/autodetect_elf_interp

共有ライブラリの ELF インタープリタ指定を自動検出
Thx eternalharvest
This commit is contained in:
stz2012 2017-12-21 23:11:32 +09:00 committed by GitHub
commit 9ac871f4c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 7 deletions

View File

@ -94,4 +94,7 @@ script:
cmake ..
make VERBOSE=1
./b25 2>&1 | grep --color=auto "ARIB STD-B25"
if [ "${TRAVIS_OS_NAME}" != "osx" ]; then
./libarib25.so 2>&1 | grep --color=auto "ARIB STD-B25"
fi
EOF

View File

@ -46,8 +46,11 @@ if(CMAKE_C_COMPILER_ID MATCHES "(GNU|Clang)")
set(CMAKE_SHARED_LINKER_FLAGS "-fvisibility=hidden")
if(UNIX AND NOT CYGWIN)
include(ElfInterp)
set(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -eshow_version")
if(NOT APPLE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-eshow_version")
endif()
else(MINGW)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--enable-stdcall-fixup -static-libgcc")
endif()

19
cmake/ElfInterp.cmake Normal file
View File

@ -0,0 +1,19 @@
find_program(OBJCOPY_EXECUTABLE "objcopy")
if(OBJCOPY_EXECUTABLE)
set(ELF_INTERP_BIN ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/elf_interp)
set(ELF_INTERP_SRC ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/elf_interp.c)
set(ELF_INTERP_DAT ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/elf_interp.dat)
file(WRITE ${ELF_INTERP_SRC} "int main(int argc, char **argv) { return 0; }")
execute_process(COMMAND ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} -o ${ELF_INTERP_BIN} ${ELF_INTERP_SRC})
execute_process(COMMAND ${OBJCOPY_EXECUTABLE} -O binary --only-section=.interp ${ELF_INTERP_BIN} ${ELF_INTERP_DAT})
if(EXISTS ${ELF_INTERP_DAT})
file(READ ${ELF_INTERP_DAT} ELF_INTERP)
string(STRIP ${ELF_INTERP} ELF_INTERP)
endif()
endif()
message(STATUS "ELF Interpreter: ${ELF_INTERP}")

View File

@ -12,4 +12,6 @@
#define BUILD_CC_VERSION "@CMAKE_C_COMPILER_VERSION@"
#define BUILD_GIT_REVISION "@GIT_REVISION@"
#define ELF_INTERP "@ELF_INTERP@"
#endif /* CONFIG_H */

View File

@ -3,17 +3,13 @@
#if defined(__GNUC__) || defined(__clang__)
# if !defined(__APPLE__)
# if defined(__x86_64__)
const char elf_interp[] __attribute__((section(".interp"))) = "/lib64/ld-linux-x86-64.so.2";
# else
const char elf_interp[] __attribute__((section(".interp"))) = "/lib/ld-linux.so.2";
# endif
const char elf_interp[] __attribute__((section(".interp"))) = ELF_INTERP;
# endif
#include <unistd.h>
void show_version(void)
{
fprintf(stderr, "libarib25.so - ARIB-STD B25 shared library version %s (%s)\n", ARIB25_VERSION_STRING, BUILD_GIT_REVISION);
fprintf(stderr, "libarib25.so - ARIB STD-B25 shared library version %s (%s)\n", ARIB25_VERSION_STRING, BUILD_GIT_REVISION);
fprintf(stderr, " built with %s %s on %s\n", BUILD_CC_NAME, BUILD_CC_VERSION, BUILD_OS_NAME);
_exit(0);
}