Opened 22 months ago
Last modified 21 months ago
#18258 closed bug
Clang should default to generating PIC — at Version 9
Reported by: | gharris | Owned by: | nobody |
---|---|---|---|
Priority: | normal | Milestone: | R1/beta5 |
Component: | - General | Version: | R1/beta4 |
Keywords: | Cc: | ||
Blocked By: | Blocking: | ||
Platform: | All |
Description (last modified by )
I'm a member of The Tcpdump Group and am working on getting our build test matrix working on Haiku (tcpdump issue 996).
We support both autotools and CMake for configuration, and are testing with both GCC and Clang.
gcc (2021_07_28) 11.2.0 from the Haiku repositories appears to have been modified to produce PIC by default and to have an -fno-pic option to get position-dependent code.
clang version 12.0.1 from the Haiku repositories has *not* been modified in this fashion, which means that, if -fPIC isn't specified, the object files it produces aren't fit for linking into an executable by default.
This not only causes problems when building tcpdump, it causes problems when performing configuration tests in both the autotools configure script and in CMake, as several of those tests involve compiling and linking test code.
That's how those tests work in autotools and CMake; it's not our scripts choosing to work that way, so this probably will affect building other software with Clang if that software uses either autotools or CMake.
We're coming up with workarounds, of varying degrees of pain, to force -fPIC to be used in *all* compiles, including those performed in autotools and CMake configuration tests, but it would probably be best if all software using autotools or CMake didn't require those workarounds in order to support building with Clang on Haiku.
Change History (9)
comment:1 by , 22 months ago
Description: | modified (diff) |
---|
comment:2 by , 22 months ago
Description: | modified (diff) |
---|
comment:3 by , 21 months ago
comment:4 by , 21 months ago
The "haiku" target configuration inside Clang is very incomplete. None the active members of the development team are especially knowledgeable about Clang internals.
There was some work here, but it is not complete and was never upstreamed: https://github.com/haikuports/haikuports/pull/4813/files
comment:5 by , 21 months ago
X512 rewrote Haiku ToolchainDirver and I added some misc changes to it. You can check this: https://github.com/zelenoviy/llvm-project/tree/llvm-haiku
Next, someone needs to create a new recipe, but I have neither the necessary knowledge nor interest in this.
comment:6 by , 21 months ago
gharris, please check with llvm12_clang-12.0.1-5 (ATM only available on x86_64).
comment:7 by , 21 months ago
llvm12_clang-12.0.1-5 works in my tests, both building a small "Hello, world!" program without -fPIC and running the tcpdump build matrix with the -fPIC changes removed from the configure script and CMakeLists.txt.
comment:8 by , 21 months ago
Description: | modified (diff) |
---|
comment:9 by , 21 months ago
Description: | modified (diff) |
---|
It appears that there's no good way to force -fPIC to be used in the very early configuration period in CMake; the only way I could find that succeeded in forcing it to be used also prevented the user from setting C compiler flags by setting the CMAKE environment variable when running CMake, which is unacceptable.
For now, we'll be attempting to catch the failure in the early configuration processes due to links failing because of non-PIC .o files and fail, in the CMake process, with a message indicate that, on Haiku, the compiler in question doesn't work well with CMake.
I *think* I can make it work with autotools.