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

configure: try to disable weak linking on OSX #309

Merged
merged 1 commit into from Feb 13, 2017

Conversation

sitsofe
Copy link
Collaborator

@sitsofe sitsofe commented Feb 13, 2017

macOS 10.12 introduced support for clock_gettime() but when compiling
with Xcode 8 (or later) and targeting 10.11 (or older) the clock_gettime
symbol is now found at configure/compile time but referenced weakly.
Running the created binary on 10.11 results in a "dyld: lazy symbol
binding failed: Symbol not found: _clock_gettime" error.

This drama has played out across other projects:

Options for working around this issue include:

  1. Turn references to functions that might be weak into compilation
    errors (-Werror=partial-availability).
  2. Disable visibility of functions that might be weak at compile link
    time (-Wl,-no_weak_imports).
  3. Change configure tests to directly check the targeted OSX version and
    fail the test if it is too old to have the required function.
  4. Make an empty function declaration marked with
    attribute((weak_import)) that is used if the symbol would
    otherwise be unavailable. It is then possible to check if the symbol
    is NULL at runtime to determine availability.

This commit does 2. when targeting the Darwin platform after checking if
the compiler/linker work with that option. It also changes the clockid_t
configure test to no longer use clock_gettime() because targeting OSX
10.11 when using the 10.12 SDK results in having the clockid_t typedef
without having the clock_gettime function. The combination of these
fixes should solve #305 .

Signed-off-by: Sitsofe Wheeler sitsofe@yahoo.com

macOS 10.12 introduced support for clock_gettime() but when compiling
with Xcode 8 (or later) and targeting 10.11 (or older) the clock_gettime
symbol is now found at configure/compile time but referenced weakly.
Running the created binary on 10.11 results in a "dyld: lazy symbol
binding failed: Symbol not found: _clock_gettime" error.

This drama has played out across other projects:
- Homebrew/homebrew-core#2674
- curl/curl#1069
- https://svn.filezilla-project.org/filezilla?view=revision&revision=7824OO
- mesonbuild/meson#949
- https://github.com/Homebrew/homebrew-core/issues?utf8=%E2%9C%93&q=label%3Aclock_gettime%20

Options for working around this issue include:
1. Turn references to functions that might be weak into compilation
   errors (-Werror=partial-availability).
2. Disable visibility of functions that might be weak at compile link
   time (-Wl,-no_weak_imports).
3. Change configure tests to directly check the targeted OSX version and
   fail the test if it is too old to have the required function.
4. Make an empty function declaration marked with
   __attribute__((weak_import)) that is used if the symbol would
   otherwise be unavailable. It is then possible to check if the symbol
   is NULL at runtime to determine availability.

This commit does 2. when targeting the Darwin platform after checking if
the compiler/linker work with that option. It also changes the clockid_t
configure test to no longer use clock_gettime() because targeting OSX
10.11 when using the 10.12 SDK results in having the clockid_t typedef
without having the clock_gettime function. The combination of these
fixes should solve axboe#305 .

Signed-off-by: Sitsofe Wheeler <sitsofe@yahoo.com>
@axboe
Copy link
Owner

axboe commented Feb 13, 2017

Nice work Sitsofe, and a most excellent commit log as well. Pulled, thanks!

@axboe axboe merged commit ccf2d89 into axboe:master Feb 13, 2017
@sitsofe sitsofe deleted the test_gettime branch February 16, 2017 22:25
s3cur3 added a commit to X-Plane/xptools_libs that referenced this pull request Mar 26, 2019
See discussion here for why the linker flags are necessary: axboe/fio#309
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

Successfully merging this pull request may close these issues.

None yet

2 participants