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

configurator: make c file name last in compiler args to workaround clang bug #11123

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

paparodeo
Copy link

@paparodeo paparodeo commented Nov 14, 2024

Re-order the compiler arguments so the c file name is last. This works around a clang bug which will suppress errors for unsupported flags if linker arguments come after the c file name. This suppression is a problem because it indicates that some argument is supported when it is not which can result in build errors.

llvm/llvm-project#116278

after this change the base module will build again with clang > 16 on systems without popcnt.
https://github.com/janestreet/base/blob/6ddf3438c79184fa443727058b623ccfe1d82ead/src/discover/discover.ml#L13-L20

eg: on aarch64 darwin and clang > 16 -mpopcnt will generate an error

$ clang -mpopcnt hello.c
clang: error: unsupported option '-mpopcnt' for target 'aarch64-apple-darwin'
$ echo $?
1

however, if appending -lpthread:

$ clang -mpopcnt hello.c -lpthread
$ echo $?
0

Which is a problem as code will assume -mpopcnt is supported and will then break later when compiling with the unsupported flag

@paparodeo paparodeo marked this pull request as draft November 14, 2024 23:58
@paparodeo paparodeo marked this pull request as ready for review November 15, 2024 00:15
Re-order the compiler arguments so the c file name is last. This works
around a clang bug which will suppress errors for unsupported flags if
linker arguments come after the c file name. This suppression is a
problem because it indicates that some argument is supported when it is
not which can result in build errors.

`https://github.com/llvm/llvm-project/issues/116278`

eg: on aarch64 darwin and clang > 16 `-mpopcnt` will generate an error

```
$ clang -mpopcnt hello.c
clang: error: unsupported option '-mpopcnt' for target 'aarch64-apple-darwin'
$ echo $?
1
```

however, if appending `-lpthread`:

```
$ clang -mpopcnt hello.c -lpthread
$ echo $?
0
```

Which is a problem as code will assume `-mpopcnt` is supported and will
then break later when compiling with the unsupported flag

Signed-off-by: Reno Dakota <paparodeo@proton.me>
@paparodeo paparodeo changed the title configurator: don't append link flags to workaround clang bug configurator: c file name is last in compiler args Nov 15, 2024
@paparodeo paparodeo changed the title configurator: c file name is last in compiler args configurator: make c file name is last in compiler args to workaround clang bug Nov 15, 2024
@paparodeo paparodeo changed the title configurator: make c file name is last in compiler args to workaround clang bug configurator: make c file name last in compiler args to workaround clang bug Nov 15, 2024
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.

1 participant