Linker flag no_weak_imports not working as expected

Originator:ePirat07
Number:rdar://34669224 Date Originated:September 27 2017, 12:31 AM
Status:Closed Resolved:
Product:Developer Tools Product Version:
Classification:Bug Reproducible:Always
 
Summary:
The `no_weak_imports` option, as the man pages say, is used to error instead of weak linking, useful for configure based projects that check if specific functions are available and if they are, use them. With weak imports it would detect them as available, even if they are not, this options seems like the perfect solution to avoid this.

Unfortunately it is not working correctly when using old deployment targets:

```
gcc -Wl,-no_weak_imports -Wl,-macosx_version_min -Wl,10.7 -mmacosx-version-min=10.7 conftest.c
```

succeeds even though it should fail.

Steps to Reproduce:
Compile attached sample conftest.c with target set to 10.7:

gcc -Wl,-no_weak_imports -Wl,-macosx_version_min -Wl,10.7 -mmacosx-version-min=10.7 conftest.c

and a second time with target set to 10.11:

gcc -Wl,-no_weak_imports -Wl,-macosx_version_min -Wl,10.11 -mmacosx-version-min=10.11 conftest.c

Expected Results:
Both should fail.

Actual Results:
Only the second one fails as expected:

Undefined symbols for architecture x86_64:
  "_mkostemp", referenced from:
      _main in conftest-ea0305.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Version/Build:
LLVM version 9.0.0, (clang-900.0.37) (static support for 21, runtime is 21)

Configuration:
macOS High Sierra 10.13 (17A365)

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!