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

macOS: Library not loaded: @rpath/libwatcher-c.0.dylib, Reason: no LC_RPATH's found #59

Closed
dunglas opened this issue Oct 24, 2024 · 8 comments

Comments

@dunglas
Copy link

dunglas commented Oct 24, 2024

After installing the library on macOS following these instructions, I get the following error:

dyld[10323]: Library not loaded: @rpath/libwatcher-c.0.dylib
  Referenced from: <8785CF2B-926F-3E20-D16E-76B30E23CA2D> /private/var/folders/nf/_zwcfbtx7m9d5g8jgympqy5r0000gn/T/go-build49046516/b237/frankenphp.test
  Reason: no LC_RPATH's found
signal: abort trap
FAIL	github.com/dunglas/frankenphp/internal/watcher	0.189s

It looks like it can be fixed in the cmake definition: https://discourse.cmake.org/t/how-to-get-an-lc-rpath-and-rpath-prefix-on-a-dylib-on-macos/5540/4

@dunglas
Copy link
Author

dunglas commented Oct 26, 2024

I'm loading the library from Go using cgo.

I fixed this by passing an explicit rpath to the linker by using the env var CGO_LDFLAGS with the following value: -lwatcher-c -lstdc++ -Wl,-rpath /usr/local/lib

@dunglas dunglas closed this as completed Oct 26, 2024
@e-dant e-dant reopened this Oct 26, 2024
@e-dant
Copy link
Owner

e-dant commented Oct 26, 2024

I think we can fix this -- I'll try to get on it today

@e-dant
Copy link
Owner

e-dant commented Oct 26, 2024

Does the next branch work ok now?

@e-dant
Copy link
Owner

e-dant commented Oct 26, 2024

Looking at this more closely, I think the issue might also involve cgo itself not adding the appropriate rpath.

libwatcher-c also probably might need an rpath on Apple to properly load libc++, but I think cgo needs to add an rpath to find libwatcher-c

@e-dant
Copy link
Owner

e-dant commented Oct 27, 2024

I ran otool on the libcwatcher on the next branch.

There's no LC_RPATH in there...

I don't know much about the linker, or linking shenanigans.

I'm not sure

  • if our CMake file's rpath handling is broken or
  • if libraries aren't candidates for having an LC_RPATH
  • if the rpath is being replaced with /what/we/set instead of an LC_RPATH being written (/usr/local/lib is used where I think I would expect an rpath?)
$ cmake -S . -B out/tmp -G 'Unix Makefiles' -DBUILD_LIB=ON -DBUILD_BIN=ON -DBUILD_HDR=ON -DBUILD_TESTING=OFF -DBUILD_SAN=OFF && cmake --build out/tmp
$ otool -l out/tmp/libwatcher-c.0.13.1.dylib
out/tmp/libwatcher-c.0.13.1.dylib:
Load command 0
      cmd LC_SEGMENT_64
  cmdsize 472
  segname __TEXT
   vmaddr 0x0000000000000000
   vmsize 0x0000000000008000
  fileoff 0
 filesize 32768
  maxprot 0x00000005
 initprot 0x00000005
   nsects 5
    flags 0x0
Section
  sectname __text
   segname __TEXT
      addr 0x000000000000498c
      size 0x000000000000331c
    offset 18828
     align 2^2 (4)
    reloff 0
    nreloc 0
     flags 0x80000400
 reserved1 0
 reserved2 0
Section
  sectname __stubs
   segname __TEXT
      addr 0x0000000000007ca8
      size 0x0000000000000288
    offset 31912
     align 2^2 (4)
    reloff 0
    nreloc 0
     flags 0x80000408
 reserved1 0 (index into indirect symbol table)
 reserved2 12 (size of stubs)
Section
  sectname __const
   segname __TEXT
      addr 0x0000000000007f30
      size 0x0000000000000020
    offset 32560
     align 2^4 (16)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Section
  sectname __cstring
   segname __TEXT
      addr 0x0000000000007f50
      size 0x000000000000004c
    offset 32592
     align 2^0 (1)
    reloff 0
    nreloc 0
     flags 0x00000002
 reserved1 0
 reserved2 0
Section
  sectname __unwind_info
   segname __TEXT
      addr 0x0000000000007f9c
      size 0x0000000000000058
    offset 32668
     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 0x0000000000008000
   vmsize 0x0000000000004000
  fileoff 32768
 filesize 16384
  maxprot 0x00000003
 initprot 0x00000003
   nsects 2
    flags 0x10
Section
  sectname __got
   segname __DATA_CONST
      addr 0x0000000000008000
      size 0x00000000000001c8
    offset 32768
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000006
 reserved1 54 (index into indirect symbol table)
 reserved2 0
Section
  sectname __const
   segname __DATA_CONST
      addr 0x00000000000081c8
      size 0x00000000000000a8
    offset 33224
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000000
 reserved1 0
 reserved2 0
Load command 2
      cmd LC_SEGMENT_64
  cmdsize 152
  segname __DATA
   vmaddr 0x000000000000c000
   vmsize 0x0000000000004000
  fileoff 0
 filesize 0
  maxprot 0x00000003
 initprot 0x00000003
   nsects 1
    flags 0x0
Section
  sectname __bss
   segname __DATA
      addr 0x000000000000c000
      size 0x0000000000000040
    offset 0
     align 2^3 (8)
    reloff 0
    nreloc 0
     flags 0x00000001
 reserved1 0
 reserved2 0
Load command 3
      cmd LC_SEGMENT_64
  cmdsize 72
  segname __LINKEDIT
   vmaddr 0x0000000000010000
   vmsize 0x0000000000004000
  fileoff 49152
 filesize 11800
  maxprot 0x00000001
 initprot 0x00000001
   nsects 0
    flags 0x0
Load command 4
          cmd LC_ID_DYLIB
      cmdsize 56
         name @rpath/libwatcher-c.0.dylib (offset 24)
   time stamp 1 Wed Dec 31 19:00:01 1969
      current version 0.13.1
compatibility version 0.0.0
Load command 5
      cmd LC_DYLD_CHAINED_FIXUPS
  cmdsize 16
  dataoff 49152
 datasize 2032
Load command 6
      cmd LC_DYLD_EXPORTS_TRIE
  cmdsize 16
  dataoff 51184
 datasize 48
Load command 7
     cmd LC_SYMTAB
 cmdsize 24
  symoff 51304
   nsyms 99
  stroff 53336
 strsize 6992
Load command 8
            cmd LC_DYSYMTAB
        cmdsize 80
      ilocalsym 0
      nlocalsym 40
     iextdefsym 40
     nextdefsym 2
      iundefsym 42
      nundefsym 57
         tocoff 0
           ntoc 0
      modtaboff 0
        nmodtab 0
   extrefsymoff 0
    nextrefsyms 0
 indirectsymoff 52888
  nindirectsyms 111
      extreloff 0
        nextrel 0
      locreloff 0
        nlocrel 0
Load command 9
     cmd LC_UUID
 cmdsize 24
    uuid 6A0D237A-B2E2-3831-9210-54291330E6A9
Load command 10
      cmd LC_BUILD_VERSION
  cmdsize 32
 platform 1
    minos 15.0
      sdk 15.0
   ntools 1
     tool 3
  version 1115.7.3
Load command 11
      cmd LC_SOURCE_VERSION
  cmdsize 16
  version 0.0
Load command 12
          cmd LC_LOAD_DYLIB
      cmdsize 104
         name /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (offset 24)
   time stamp 2 Wed Dec 31 19:00:02 1969
      current version 3038.1.255
compatibility version 150.0.0
Load command 13
          cmd LC_LOAD_DYLIB
      cmdsize 104
         name /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (offset 24)
   time stamp 2 Wed Dec 31 19:00:02 1969
      current version 1226.0.0
compatibility version 1.0.0
Load command 14
          cmd LC_LOAD_DYLIB
      cmdsize 48
         name /usr/lib/libc++.1.dylib (offset 24)
   time stamp 2 Wed Dec 31 19:00:02 1969
      current version 1800.101.0
compatibility version 1.0.0
Load command 15
          cmd LC_LOAD_DYLIB
      cmdsize 56
         name /usr/lib/libSystem.B.dylib (offset 24)
   time stamp 2 Wed Dec 31 19:00:02 1969
      current version 1351.0.0
compatibility version 1.0.0
Load command 16
      cmd LC_FUNCTION_STARTS
  cmdsize 16
  dataoff 51232
 datasize 72
Load command 17
      cmd LC_DATA_IN_CODE
  cmdsize 16
  dataoff 51304
 datasize 0
Load command 18
      cmd LC_CODE_SIGNATURE
  cmdsize 16
  dataoff 60336
 datasize 616

@dunglas
Copy link
Author

dunglas commented Oct 27, 2024

Maybe this SO answer can help: https://stackoverflow.com/a/71321163/1352334

@e-dant
Copy link
Owner

e-dant commented Oct 27, 2024

I think the current state of the next branch might be ok. AFAICT:

  • The libc++ that libwatcher-c wants doesn't load with an RPATH. I don't know if this is undesirable or not.
  • Any (Apple) binaries that link to libwatcher-c need an rpath (to where libwatcher-c lives: /usr/local/lib on macOS)

@e-dant
Copy link
Owner

e-dant commented Oct 27, 2024

  • The libc++ that libwatcher-c wants doesn't load with an RPATH. I don't know if this is undesirable or not.

(IOW, I don't know if we need an LC_RPATH in the library, since it seems unused)

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

2 participants