Skip to content

Commit

Permalink
Issue SimonKagstrom#256: system-mode: Build 32-bit version of binary lib
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonKagstrom committed Jun 20, 2018
1 parent 9db5fa5 commit fdfbfb3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
19 changes: 18 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,12 @@ target_link_libraries(kcov_system_lib
${ZLIB_LIBRARIES}
)

add_library (kcov_system_lib_32 SHARED engines/system-mode-binary-lib.cc utils.cc system-mode/registration.cc)
set_target_properties(kcov_system_lib_32 PROPERTIES SUFFIX ".so" COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
target_link_libraries(kcov_system_lib_32
"${DL_LIBRARY}"
)


add_custom_command(
OUTPUT library.cc
Expand Down Expand Up @@ -333,6 +339,17 @@ add_custom_command(
"${CMAKE_CURRENT_SOURCE_DIR}/bin-to-c-source.py"
)

add_custom_command(
OUTPUT kcov-system-library-32.cc
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/bin-to-c-source.py"
$<TARGET_FILE:kcov_system_lib_32>
kcov_system_library_32
> kcov-system-library-32.cc
DEPENDS
kcov_system_lib_32
"${CMAKE_CURRENT_SOURCE_DIR}/bin-to-c-source.py"
)

add_custom_command(
OUTPUT python-helper.cc
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/bin-to-c-source.py"
Expand Down Expand Up @@ -401,7 +418,7 @@ if (SPECIFY_RPATH)
endif (SPECIFY_RPATH)

if (LIBELF_FOUND)
add_executable (${KCOV} ${${KCOV}_SRCS} ${SOLIB_generated} bash-redirector-library.cc python-helper.cc bash-helper.cc kcov-system-library.cc html-data-files.cc version.c)
add_executable (${KCOV} ${${KCOV}_SRCS} ${SOLIB_generated} bash-redirector-library.cc python-helper.cc bash-helper.cc kcov-system-library.cc kcov-system-library-32.cc html-data-files.cc version.c)

target_link_libraries(${KCOV}
stdc++
Expand Down
5 changes: 4 additions & 1 deletion src/engines/system-mode-engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <configuration.hh>
#include <output-handler.hh>
#include <utils.hh>
#include <capabilities.hh>
#include <generated-data-base.hh>

#include <stdlib.h>
Expand Down Expand Up @@ -139,8 +140,10 @@ class SystemModeEngine : public IEngine

free((void *)data);

ICapabilities &capabilities = ICapabilities::getInstance();

std::string patchelf = conf.keyAsString("patchelf-command");
std::string lib = "libkcov_system.so";
std::string lib = capabilities.hasCapability("64bit") ? "libkcov_system.so" : "libkcov_system_32.so";
std::string cmd = fmt("%s --add-needed %s %s", patchelf.c_str(), lib.c_str(), dst.c_str());

// FIXME! Check if patchelf exists
Expand Down
10 changes: 7 additions & 3 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
using namespace kcov;

extern GeneratedData kcov_system_library_data;
extern GeneratedData kcov_system_library_32_data;

static IEngine *g_engine;
static IOutputHandler *g_output;
Expand Down Expand Up @@ -402,15 +403,18 @@ static int runSystemModeRecord()
(void)mkdir(lib.c_str(), 0755);

std::string library = fmt("%s/libkcov_system.so", lib.c_str());
std::string library32 = fmt("%s/libkcov_system_32.so", lib.c_str());

if (write_file(kcov_system_library_data.data(), kcov_system_library_data.size(),
"%s", library.c_str()) < 0)
"%s", library.c_str()) < 0 ||
write_file(kcov_system_library_32_data.data(), kcov_system_library_32_data.size(),
"%s", library32.c_str()) < 0)
{
error("Can't write binary library at %s", library.c_str());
error("Can't write binary library at %s/%s", library.c_str(), library32.c_str());

return -1;
}
if (chmod(library.c_str(), 0755) < 0)
if (chmod(library.c_str(), 0755) < 0 || chmod(library32.c_str(), 0755) < 0)
{
error("Can't chmod??\n");
}
Expand Down
10 changes: 10 additions & 0 deletions src/parsers/elf-parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ class ElfInstance : public IFileParser, IFileParser::ILineListener

m_elfIs32Bit = raw[EI_CLASS] == ELFCLASS32;

if (m_elfIs32Bit)
{
capabilities.removeCapability("64bit");
}
else
{
capabilities.addCapability("64bit");
}


if (elfIs64Bit() != machine_is_64bit())
capabilities.removeCapability("handle-solibs");
else
Expand Down

0 comments on commit fdfbfb3

Please sign in to comment.