Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openjpeg doesn't install a relocatable shared lib on macOS #1404

Closed
SpaceIm opened this issue Jan 25, 2022 · 0 comments
Closed

openjpeg doesn't install a relocatable shared lib on macOS #1404

SpaceIm opened this issue Jan 25, 2022 · 0 comments

Comments

@SpaceIm
Copy link

SpaceIm commented Jan 25, 2022

openjpeg CMakeLists unconditionally (and surprisingly) changes INSTALL_NAME_DIR property of openjp2 target if Apple:

list(APPEND OPENJPEG_LIBRARY_PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${OPENJPEG_INSTALL_LIB_DIR}")

This leads to a hardcoded path in installed shared lib, which shouldn't be the default behavior for sure. Default CMake behavior is to install relocatable runtimes on macOS with @rpath/<libname>, if https://cmake.org/cmake/help/v3.0/policy/CMP0042.html is NEW (which is the case in openjpeg CMakeLists, this is why it's very surprising to see this hardcoded INSTALL_NAME).

I would expect this after running otool -l libopenjp2.2.4.0.dylib (relevant part in this output is name @rpath/libopenjp2.7.dylib (offset 24)):

libopenjp2.2.4.0.dylib:
Load command 0
      cmd LC_SEGMENT_64
  cmdsize 472
  segname __TEXT
   vmaddr 0x0000000000000000
   vmsize 0x0000000000054000
  fileoff 0
 filesize 344064
  maxprot 0x00000005
 initprot 0x00000005
   nsects 5
    flags 0x0
Section
  sectname __text
   segname __TEXT
      addr 0x00000000000043e0
      size 0x0000000000048181
    offset 17376
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x80000400
 reserved1 0
 reserved2 0
Section
  sectname __stubs
   segname __TEXT
      addr 0x000000000004c562
      size 0x0000000000000102
    offset 312674
     align 2^1 (2)
    reloff 0
    nreloc 0
     flags 0x80000408
 reserved1 0 (index into indirect symbol table)
 reserved2 6 (size of stubs)
Section
  sectname __const
   segname __TEXT
      addr 0x000000000004c670
      size 0x000000000000162c
    offset 312944
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __cstring
   segname __TEXT
      addr 0x000000000004dca0
      size 0x0000000000005ffa
    offset 318624
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x00000002
 reserved1 0
 reserved2 0
Section
  sectname __unwind_info
   segname __TEXT
      addr 0x0000000000053c9c
      size 0x0000000000000360
    offset 343196
     align 2^2 (4)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Load command 1
      cmd LC_SEGMENT_64
  cmdsize 232
  segname __DATA_CONST
   vmaddr 0x0000000000054000
   vmsize 0x0000000000004000
  fileoff 344064
 filesize 16384
  maxprot 0x00000003
 initprot 0x00000003
   nsects 2
    flags 0x10
Section
  sectname __got
   segname __DATA_CONST
      addr 0x0000000000054000
      size 0x0000000000000168
    offset 344064
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000006
 reserved1 43 (index into indirect symbol table)
 reserved2 0
Section
  sectname __const
   segname __DATA_CONST
      addr 0x0000000000054170
      size 0x0000000000000b20
    offset 344432
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Load command 2
      cmd LC_SEGMENT_64
  cmdsize 72
  segname __LINKEDIT
   vmaddr 0x0000000000058000
   vmsize 0x0000000000008000
  fileoff 360448
 filesize 25072
  maxprot 0x00000001
 initprot 0x00000001
   nsects 0
    flags 0x0
Load command 3
          cmd LC_ID_DYLIB
      cmdsize 56
         name @rpath/libopenjp2.7.dylib (offset 24)
   time stamp 1 Thu Jan  1 01:00:01 1970
      current version 2.4.0
compatibility version 7.0.0
Load command 4
      cmd LC_DYLD_CHAINED_FIXUPS
  cmdsize 16
  dataoff 360448
 datasize 816
Load command 5
      cmd LC_DYLD_EXPORTS_TRIE
  cmdsize 16
  dataoff 361264
 datasize 5512
Load command 6
     cmd LC_SYMTAB
 cmdsize 24
  symoff 367496
   nsyms 469
  stroff 375352
 strsize 10168
Load command 7
            cmd LC_DYSYMTAB
        cmdsize 80
      ilocalsym 0
      nlocalsym 165
     iextdefsym 165
     nextdefsym 259
      iundefsym 424
      nundefsym 45
         tocoff 0
           ntoc 0
      modtaboff 0
        nmodtab 0
   extrefsymoff 0
    nextrefsyms 0
 indirectsymoff 375000
  nindirectsyms 88
      extreloff 0
        nextrel 0
      locreloff 0
        nlocrel 0
Load command 8
     cmd LC_UUID
 cmdsize 24
    uuid C707145F-7276-3E43-A8ED-014C266E0EED
Load command 9
      cmd LC_BUILD_VERSION
  cmdsize 32
 platform 1
    minos 12.0
      sdk 12.1
   ntools 1
     tool 3
  version 711.0
Load command 10
      cmd LC_SOURCE_VERSION
  cmdsize 16
  version 0.0
Load command 11
          cmd LC_LOAD_DYLIB
      cmdsize 56
         name /usr/lib/libSystem.B.dylib (offset 24)
   time stamp 2 Thu Jan  1 01:00:02 1970
      current version 1311.0.0
compatibility version 1.0.0
Load command 12
      cmd LC_FUNCTION_STARTS
  cmdsize 16
  dataoff 366776
 datasize 632
Load command 13
      cmd LC_DATA_IN_CODE
  cmdsize 16
  dataoff 367408
 datasize 88

But currently, I get this in relevant part which makes the shared lib non-relocatable:

Load command 3
          cmd LC_ID_DYLIB
      cmdsize 152
         name /Users/spaceim/.conan/data/openjpeg/2.3.1/_/_/package/bda713dd3b257827c8d11a06ac9d824038871572/lib/libopenjp2.7.dylib (offset 24)
   time stamp 1 Thu Jan  1 01:00:01 1970
      current version 2.3.1
compatibility version 7.0.0

This absolute path should just be @rpath/libopenjp2.7.dylib on macOS.

If openjpeg really wants to hardcode a path in shared lib of the install tree on macOS, at least it would be nice to provide an option to generate relocatable binaries.

But honestly, INSTALL_NAME_DIR shouldn't be hardcoded in a CMakeLists, it should be injected externally with CMAKE_INSTALL_NAME_DIR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant