The configuration for -fPIC in the builtins library when built standalone is unconditional, stating that the flags would "normally be added... by the llvm cmake step" This is untrue, as the llvm cmake step checks LLVM_ENABLE_PIC, which allows a client to turn off -fPIC. I've added an option when compiler-rt builtins are configured standalone, such as when built as part of the LLVM runtimes system, to guard the application of -fPIC for users that want it.
I think this changes the existing behavior. COMPILER_RT_STANDALONE_BUILD is set when compiler-rt is being built as a standalone project, which is not only when being built as part of runtimes, but also when you run CMake in compiler-rt as the source directory. In that case, COMPILER_RT_BUILTINS_ENABLE_PIC` will be unset because the new option is only defined when compiler-rt/lib/builtins is the root source directory, and -fPIC will be dropped in that case. This new option has to be defined in this block as well: https://github.com/llvm/llvm-project/blob/master/compiler-rt/CMakeLists.txt#L76 to avoid changing the current behavior in the standalone case.
Adding the option to the top-level block is undesirable, as that splits the option origin into two different places, since we need it both when builtins is the top-level, and when compiler-rt is the top-level.
Would adding the option in a block guarded by COMPILER_RT_STANDALONE_BUILD outside and just after of the SOURCE_DIR check it's currently in be a good alternative? That should fire in all cases of COMPILER_RT_STANDALONE_BUILD.
I'll upload the change when I get a chance, in case my description is confusing.