Uploaded image for project: 'WiredTiger'
  1. WiredTiger
  2. WT-8714

Support linking CMake test binaries with a relative RPATH

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • WT11.0.0, 5.3.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • 5
    • Storage - Ra 2022-02-07, Storage - Ra 2022-02-21

      Summary
      Currently our test binaries are linked with an absolute RPATH to the WiredTiger library under the build directory (when building a shared WT library). This ticket should introduce support for optionally linking our test binaries with a relative RPATH to the WiredTiger library (rather than an absolute path).

      Motivation
      When debugging core dumps of WiredTiger, we often need to fetch the build artifacts and load the test binary through gdb. When we do this however, the RPATH is an absolute path relating to the Evergreen machine i.e.

      $ objdump -p cmake_build/test/format/t
      
      cmake_build/test/format/t: file format elf64-x86-64
      ...
      Dynamic Section:
        NEEDED               libwiredtiger.so.10.0.2
        NEEDED               libpthread.so.0
        NEEDED               librt.so.1
        NEEDED               libdl.so.2
        NEEDED               libm.so.6
        NEEDED               libgcc_s.so.1
        NEEDED               libc.so.6
        RPATH                /data/mci/a623bbdb33ea4650ef39183c092a5407/wiredtiger/cmake_build
        INIT                 0x000000000041df30
        FINI                 0x0000000000533564
        PREINIT_ARRAY        0x0000000000790118
        PREINIT_ARRAYSZ      0x0000000000000008
        INIT_ARRAY           0x0000000000790120
        INIT_ARRAYSZ         0x00000000000000b0
        FINI_ARRAY           0x00000000007901d0
        FINI_ARRAYSZ         0x00000000000000b0
        HASH                 0x00000000004002b0
        GNU_HASH             0x0000000000403058
        STRTAB               0x0000000000411570
        SYMTAB               0x0000000000406458
        STRSZ                0x000000000000af42
        SYMENT               0x0000000000000018
        DEBUG                0x0000000000000000
        PLTGOT               0x0000000000791000
        PLTRELSZ             0x0000000000000888
        PLTREL               0x0000000000000007
        JMPREL               0x000000000041d6a8
        RELA                 0x000000000041d498
        RELASZ               0x0000000000000210
        RELAENT              0x0000000000000018
        VERNEED              0x000000000041d378
        VERNEEDNUM           0x0000000000000006
        VERSYM               0x000000000041c4b2
      

      The 'data/mci/<hash>/wiredtiger/cmake_build' is obviously non-portable and as a result of the above, when either locally executing the test executable or running it through gdb, we need to manually intervene to point the runpath to the WiredTiger library. This is particularly confusing when needing to debug evergreen failures.

      As we generally don't distribute/install test binaries, we can usually expect to execute a test under a build directory path. Thus linking a relative RPATH in our test binaries should be something we can reasonably support (I wouldn't extend this feature to other binaries however e.g. 'wt').

      Acceptance Criteria (Definition of Done)

      • Introduce a new CMake configuration option i.e. 'LINK_TESTS_WITH_RELATIVE_RPATH', that when enabled, ensures test binaries (only test binaries) are linked with a relative path to the WiredTiger library under the build directory.
        • This for example can be achieved via linker flags e.g. '-Wl,-rpath,$ORIGIN/../../' (Linux), '-Wl,-rpath,@loader_path/../../' (Darwin)
        • The new configuration option can just be bounded to Linux and Darwin systems as an initial pass ($ORIGIN/@loader_path are OS-dependent).
        • A good place to add this in CMake would be in our 'create_test_executable' helper, ensuring the setting is propagated to all our test binaries e.g. 'set_target_properties(${target} PROPERTIES LINK_FLAGS "<flags>")'
      • Validate the compiled test executable contains a relative rpath after its been built i.e. checking 'ldd' resolves the WiredTiger library via a relative rpath or checking the Dynamic Section table via 'objdump' (or otool on MacOS).
        • Ensure this is only applied to test binaries, not appearing in any of our other build artifacts.
      • Ensure the new configuration option is used for evergreen testing.

            Assignee:
            siddhartha.mahajan@mongodb.com Sid Mahajan
            Reporter:
            alison.felizzi@mongodb.com Alison Felizzi (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: