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

os/mac/pkgconfig: use ${homebrew_sdkroot}/usr/lib for libffi #10079

Closed
wants to merge 1 commit into from

Conversation

kou
Copy link
Contributor

@kou kou commented Dec 21, 2020

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?
    • No. Some tests are failed but they aren't related to this change. They may be caused by my environment.
    • I want to see CI result.
  • Have you successfully run brew man locally and committed any changes?

We need to use ${homebrew_sdkroot}/usr/lib/libffi.tbd not
/usr/lib/libffi.dylib to use libffi with
${homebrew_sdkroot}/usr/include/ffi/ffi.h. If we use
/usr/lib/libffi.dylib directly,
${homebrew_sdkroot}/usr/include/ffi/ffi.h and -lffi are inconsistent.

For example, ${homebrew_sdkroot}/usr/include/ffi/ffi.h for 10.14
doesn't provide ffi_prep_cif_var() but -lffi accept it.

a.c:

#include <ffi.h>

int
main(void)
{
  ffi_prep_cif_var(NULL, 0, 0, 0, 0, NULL);
  return 0;
}

No declaration error is expected, OK:

$ gcc $(PKG_CONFIG_PATH=$(brew --prefix)/Homebrew/Library/Homebrew/os/mac/pkgconfig/10.14 pkg-config --cflags --libs libffi) a.c
a.c:6:3: error: implicit declaration of function 'ffi_prep_cif_var' is invalid in C99
      [-Werror,-Wimplicit-function-declaration]
  ffi_prep_cif_var(NULL, 0, 0, 0, 0, NULL);
  ^
a.c:6:3: note: did you mean 'ffi_prep_cif'?
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/ffi/ffi.h:312:1: note: 'ffi_prep_cif' declared here
ffi_prep_cif(
^
1 error generated.

Ignoring no declaration error. It must be a link error. NG:

$ gcc -Wno-implicit-function-declaration $(PKG_CONFIG_PATH=$(brew --prefix)/Homebrew/Library/Homebrew/os/mac/pkgconfig/10.14 pkg-config --cflags --libs libffi) a.c
(no error, unexpected)

With this change: Ignoring no declaration error. It must be a link error. OK:

$ gcc -Wno-implicit-function-declaration $(PKG_CONFIG_PATH=$(brew --prefix)/Homebrew/Library/Homebrew/os/mac/pkgconfig/10.14 pkg-config --cflags --libs libffi) a.c
Undefined symbols for architecture x86_64:
  "_ffi_prep_cif_var", referenced from:
      _main in a-ae3840.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Context: ruby/fiddle#52

We need to use ${homebrew_sdkroot}/usr/lib/libffi.tbd not
/usr/lib/libffi.dylib to use libffi with
${homebrew_sdkroot}/usr/include/ffi/ffi.h. If we use
/usr/lib/libffi.dylib directly,
${homebrew_sdkroot}/usr/include/ffi/ffi.h and -lffi are inconsistent.

For example, ${homebrew_sdkroot}/usr/include/ffi/ffi.h for 10.14
doesn't provide ffi_prep_cif_var() but -lffi accept it.

a.c:

    #include <ffi.h>

    int
    main(void)
    {
      ffi_prep_cif_var(NULL, 0, 0, 0, 0, NULL);
      return 0;
    }

No declaration error is expected, OK:

    $ gcc $(PKG_CONFIG_PATH=$(brew --prefix)/Homebrew/Library/Homebrew/os/mac/pkgconfig/10.14 pkg-config --cflags --libs libffi) a.c
    a.c:6:3: error: implicit declaration of function 'ffi_prep_cif_var' is invalid in C99
          [-Werror,-Wimplicit-function-declaration]
      ffi_prep_cif_var(NULL, 0, 0, 0, 0, NULL);
      ^
    a.c:6:3: note: did you mean 'ffi_prep_cif'?
    /Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/usr/include/ffi/ffi.h:312:1: note: 'ffi_prep_cif' declared here
    ffi_prep_cif(
    ^
    1 error generated.

Ignoring no declaration error. It must be a link error. NG:

    $ gcc -Wno-implicit-function-declaration $(PKG_CONFIG_PATH=$(brew --prefix)/Homebrew/Library/Homebrew/os/mac/pkgconfig/10.14 pkg-config --cflags --libs libffi) a.c
    (no error, unexpected)

With this change: Ignoring no declaration error. It must be a link error. OK:

    $ gcc -Wno-implicit-function-declaration $(PKG_CONFIG_PATH=$(brew --prefix)/Homebrew/Library/Homebrew/os/mac/pkgconfig/10.14 pkg-config --cflags --libs libffi) a.c
    Undefined symbols for architecture x86_64:
      "_ffi_prep_cif_var", referenced from:
          _main in a-ae3840.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

Context: ruby/fiddle#52
@kou kou force-pushed the libffi-pc-sdkroot branch from 427f0c8 to 829c326 Compare December 21, 2020 03:19
@MikeMcQuaid MikeMcQuaid requested review from Bo98, reitermarkus and a team and removed request for Bo98 December 21, 2020 08:22
@Bo98
Copy link
Member

Bo98 commented Dec 21, 2020

The change seems reasonable and technically more correct (if applied consistently across all libraries - not just libffi), but the real cause of the error you saw was because the wrong headers were being used for the system. 10.14 SDK headers should not be used on Catalina (10.15). That's why the mismatch between library and headers occur.

I suspect the user is using an old build of pkg-config and the problem will go away with a brew reinstall pkgconfig. There is plans to detect this issue and auto-prompt reinstalling pkg-config (I should probably open an issue detailing it).

@MikeMcQuaid
Copy link
Member

I should probably open an issue detailing it

@Bo98 yup, that'd be great, thanks ❤️

@MikeMcQuaid
Copy link
Member

I suspect the user is using an old build of pkg-config and the problem will go away with a brew reinstall pkgconfig. There is plans to detect this issue and auto-prompt reinstalling pkg-config (I should probably open an issue detailing it).

@kou could you try this?

@kou
Copy link
Contributor Author

kou commented Dec 22, 2020

I'm sorry but I can't try it because I don't have an environment that reproduces this case.

@escogido Could you try the following command lines?

$ gem install fiddle:1.0.4 # This will be failed.
$ brew reinstall pkgconfig
$ gem install fiddle:1.0.4 # This will not be failed.

@MikeMcQuaid
Copy link
Member

Thanks for the PR @kou but passing on this until we find someone who is affected by this who can test reproduce steps.

@kou kou deleted the libffi-pc-sdkroot branch December 23, 2020 09:56
@BrewTestBot BrewTestBot added the outdated PR was locked due to age label Jan 25, 2021
@Homebrew Homebrew locked as resolved and limited conversation to collaborators Jan 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants