Monday, June 12, 2023

devel/llvm: sync with base

The diff below syncs the devel/llvm port with the numerous changes
that have been applied to base llvm since the import of LLVM 13.0.

I have been unable to add this one commit, because the files it
modifies don't exist in the LLVM source tree:

| commit 5e1c9963cb8a2244fbe31d5e8594b757051ef3eb
| from: gnezdo <gnezdo@openbsd.org>
| date: Wed Feb 16 03:48:55 2022 UTC
|
| Add ifdefs to build ubsan_minimal on OpenBSD
|
| ok jca@
|
| M gnu/llvm/compiler-rt/lib/interception/interception.h
| M gnu/llvm/compiler-rt/lib/interception/interception_linux.h
| M gnu/llvm/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
| M gnu/llvm/compiler-rt/lib/sanitizer_common/sanitizer_linux.h
| M gnu/llvm/compiler-rt/lib/sanitizer_common/sanitizer_platform.h
| M gnu/llvm/compiler-rt/lib/ubsan/ubsan_platform.h

Here's the diff that syncs the other 39 src commits.
Comments? Anybody want to double check (hahaha)?
OK?

-----------------------------------------------
commit 43b651f79bd9c05efac60f8f453f01ba2377a626 (ibt)
from: Christian Weisgerber <naddy@mips.inka.de>
date: Mon Jun 12 19:47:35 2023 UTC

devel/llvm: sync with base

Catch up with the changes to base LLVM since the import of 13.0:
* lld: do not report undefined weak references in shared libraries
* lld: restore upstream default for --[no-]allow-shlib-undefined
* add a dummy -t flag to llvm-ranlib to match binutils' ranlib's -t flag
* Enable unwind tables on all clang architectures.
* Report versioned lib.so in cc --print-file-name given short name
* Arm is not ready for unwinding yet. Disable unwind info generation for now.
* Downgrade RISCV ABI mismatch error to a warning
* Our malloc(3) guarantees 16-byte alignment.
* support more than one input file in llvm-ranlib
* In the linkers, collect objects in section "openbsd.mutable"
* Recognize PT_OPENBSD_MUTABLE with LLVM's readobj / objdump.
* add .gnu.warning.SYMBOL support to ld.lld(1)
* correct alignment
* Downgrade riscv64-specific LTO error to a warning
* accept --executable-only on aarch64, riscv64, and mips64
* arm64 and riscv64 can now do --execute-only by default
* Allow people to try --execute-only on amd64 and sparc64.
* Update the list of architectures where clang will accept the --execute-only option
* enable --exec-only as default on AMD64
* permit -execute-only on ppc64 (not default)
* Change the emitted .glink stub on powerpc64 to use an instruction sequence
* Make --execute-only the default on powerpc64.
* Permit the --exec-only option on i386 also.
* 32-bit powerpc should also allow the --exec-only flag.
* sync --execute-only archs described in the manual with current code
* make --execute-only the default on powerpc
* default sparc64 ld.lld to --execute-only
* switch mips64 ld.lld to execute-only
* allow out-of-class defaulting of comparison operators
* Make -mbranch-protection=bti the default on OpenBSD.
* Implement support for PT_OPENBSD_NOBTCFI in lld(1).
* Don't create IBT .plt if there are no PLT entries.
* On openbsd amd64, emit IBT endbr64 instructions by default
* On openbsd amd64, the compiler has been found to generate some nasty jump table
* Enable kernel-address sanitizer for clang openbsd target
* Turn on pointer-authentication on arm64 as well by default.
* Enable BTI PLT entries by default.
* Add IBT support to the retpoline PLTs.
* Add IBT support to the retpoline+znow PLTs

M devel/llvm/Makefile
A devel/llvm/patches/patch-docs_CommandGuide_llvm-ranlib_rst
A devel/llvm/patches/patch-include_llvm_BinaryFormat_ELF_h
M devel/llvm/patches/patch-tools_clang_include_clang_Basic_DiagnosticSemaKinds_td
A devel/llvm/patches/patch-tools_clang_lib_Basic_TargetInfo_cpp
M devel/llvm/patches/patch-tools_clang_lib_Driver_ToolChains_Clang_cpp
A devel/llvm/patches/patch-tools_clang_lib_CodeGen_CodeGenModule_cpp
M devel/llvm/patches/patch-tools_clang_lib_Driver_ToolChains_OpenBSD_cpp
A devel/llvm/patches/patch-tools_clang_lib_Driver_Driver_cpp
M devel/llvm/patches/patch-tools_clang_lib_Driver_ToolChains_OpenBSD_h
M devel/llvm/patches/patch-tools_lld_ELF_Config_h
M devel/llvm/patches/patch-tools_lld_ELF_DriverUtils_cpp
M devel/llvm/patches/patch-tools_lld_ELF_Driver_cpp
A devel/llvm/patches/patch-tools_clang_lib_Sema_SemaDeclCXX_cpp
M devel/llvm/patches/patch-tools_lld_ELF_Symbols_h
A devel/llvm/patches/patch-tools_lld_ELF_Arch_AArch64_cpp
M devel/llvm/patches/patch-tools_lld_ELF_Writer_cpp
A devel/llvm/patches/patch-tools_lld_ELF_Arch_PPC64_cpp
A devel/llvm/patches/patch-tools_lld_ELF_Arch_RISCV_cpp
A devel/llvm/patches/patch-tools_lld_ELF_Arch_X86_64_cpp
A devel/llvm/patches/patch-tools_lld_ELF_InputFiles_cpp
A devel/llvm/patches/patch-tools_lld_ELF_InputFiles_h
A devel/llvm/patches/patch-tools_lld_ELF_Relocations_cpp
A devel/llvm/patches/patch-tools_lld_ELF_ScriptParser_cpp
A devel/llvm/patches/patch-tools_lld_ELF_SymbolTable_cpp
A devel/llvm/patches/patch-tools_lld_ELF_SyntheticSections_cpp
A devel/llvm/patches/patch-tools_lld_ELF_SyntheticSections_h
A devel/llvm/patches/patch-tools_lld_docs_ld_lld_1
A devel/llvm/patches/patch-tools_llvm-ar_llvm-ar_cpp
A devel/llvm/patches/patch-tools_llvm-objdump_ELFDump_cpp
A devel/llvm/patches/patch-tools_llvm-readobj_ELFDumper_cpp

diff 39f5d67808d92409f719d5468dfebacadfb0376d 43b651f79bd9c05efac60f8f453f01ba2377a626
commit - 39f5d67808d92409f719d5468dfebacadfb0376d
commit + 43b651f79bd9c05efac60f8f453f01ba2377a626
blob - c2dbce1980c80a8787eee7e69b3552d48f8dead4
blob + 8f76f56849eb1b9e680935cd1194d8bdb59bdc54
--- devel/llvm/Makefile
+++ devel/llvm/Makefile
@@ -15,7 +15,7 @@ REVISION-main = 5
PKGSPEC-main = llvm-=${LLVM_V}
PKGNAME-python = py3-llvm-${LLVM_V}
PKGNAME-lldb = lldb-${LLVM_V}
-REVISION-main = 5
+REVISION-main = 6
REVISION-lldb = 1
REVISION-python = 0

blob - /dev/null
blob + 2db158b6933509e5719b11281b7dc1355abd29df (mode 644)
--- /dev/null
+++ devel/llvm/patches/patch-docs_CommandGuide_llvm-ranlib_rst
@@ -0,0 +1,21 @@
+- support more than one input file in llvm-ranlib
+
+Index: docs/CommandGuide/llvm-ranlib.rst
+--- docs/CommandGuide/llvm-ranlib.rst.orig
++++ docs/CommandGuide/llvm-ranlib.rst
+@@ -6,13 +6,13 @@ llvm-ranlib - generates an archive index
+ SYNOPSIS
+ --------
+
+-:program:`llvm-ranlib` [*options*]
++:program:`llvm-ranlib` [*options*] *archive ...*
+
+ DESCRIPTION
+ -----------
+
+ :program:`llvm-ranlib` is an alias for the :doc:`llvm-ar <llvm-ar>` tool that
+-generates an index for an archive. It can be used as a replacement for GNU's
++generates an index for one or more archives. It can be used as a replacement for GNU's
+ :program:`ranlib` tool.
+
+ Running :program:`llvm-ranlib` is equivalent to running ``llvm-ar s``.
blob - /dev/null
blob + 40cfe8c92183743ce653efd25c046460c4323d9b (mode 644)
--- /dev/null
+++ devel/llvm/patches/patch-include_llvm_BinaryFormat_ELF_h
@@ -0,0 +1,20 @@
+- In the linkers, collect objects in section "openbsd.mutable" and place
+ them into a page-aligned region in the bss, with the right markers for
+ kernel/ld.so to identify the region and skip making it immutable.
+- Implement support for PT_OPENBSD_NOBTCFI in lld(1). This can be set using
+ the -z nobtcfi option.
+
+Index: include/llvm/BinaryFormat/ELF.h
+--- include/llvm/BinaryFormat/ELF.h.orig
++++ include/llvm/BinaryFormat/ELF.h
+@@ -1303,8 +1303,10 @@ enum {
+ PT_GNU_RELRO = 0x6474e552, // Read-only after relocation.
+ PT_GNU_PROPERTY = 0x6474e553, // .note.gnu.property notes sections.
+
++ PT_OPENBSD_MUTABLE = 0x65a3dbe5, // Like bss, but not immutable.
+ PT_OPENBSD_RANDOMIZE = 0x65a3dbe6, // Fill with random data.
+ PT_OPENBSD_WXNEEDED = 0x65a3dbe7, // Program does W^X violations.
++ PT_OPENBSD_NOBTCFI = 0x65a3dbe8, // Do not enforce branch target CFI
+ PT_OPENBSD_BOOTDATA = 0x65a41be6, // Section for boot arguments.
+
+ // ARM program header types.
blob - 20179a5326226a8bcd09992e427b94e98c049d91
blob + effb07ea0b6851dd191f532f28c46a724b909598
--- devel/llvm/patches/patch-tools_clang_include_clang_Basic_DiagnosticSemaKinds_td
+++ devel/llvm/patches/patch-tools_clang_include_clang_Basic_DiagnosticSemaKinds_td
@@ -9,6 +9,10 @@ Index: tools/clang/include/clang/Basic/DiagnosticSemaK

- Add a new warning for %n format specifier usage in printf(3) family functions

+- allow out-of-class defaulting of comparison operators
+ this is backport of the following upstream commit:
+ commit 5fbe21a7748f91adbd1b16c95bbfe180642320a3
+
Index: tools/clang/include/clang/Basic/DiagnosticSemaKinds.td
--- tools/clang/include/clang/Basic/DiagnosticSemaKinds.td.orig
+++ tools/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -30,7 +34,33 @@ Index: tools/clang/include/clang/Basic/DiagnosticSemaK
def err_typecheck_convert_incompatible_pointer_sign :
Error<ext_typecheck_convert_incompatible_pointer_sign.Text>;
def ext_typecheck_convert_incompatible_pointer : ExtWarn<
-@@ -9512,6 +9512,9 @@ def err_os_log_argument_too_big : Error<
+@@ -9100,15 +9100,22 @@ def warn_cxx17_compat_defaulted_comparison : Warning<
+ "before C++20">, InGroup<CXXPre20Compat>, DefaultIgnore;
+ def err_defaulted_comparison_template : Error<
+ "comparison operator template cannot be defaulted">;
+-def err_defaulted_comparison_out_of_class : Error<
+- "%sub{select_defaulted_comparison_kind}0 can only be defaulted in a class "
+- "definition">;
++def err_defaulted_comparison_num_args : Error<
++ "%select{non-member|member}0 %sub{select_defaulted_comparison_kind}1"
++ " comparison operator must have %select{2|1}0 parameters">;
+ def err_defaulted_comparison_param : Error<
+ "invalid parameter type for defaulted %sub{select_defaulted_comparison_kind}0"
+ "; found %1, expected %2%select{| or %4}3">;
++def err_defaulted_comparison_param_unknown : Error<
++ "invalid parameter type for non-member defaulted"
++ " %sub{select_defaulted_comparison_kind}0"
++ "; found %1, expected class or reference to a constant class">;
+ def err_defaulted_comparison_param_mismatch : Error<
+ "parameters for defaulted %sub{select_defaulted_comparison_kind}0 "
+ "must have the same type%diff{ (found $ vs $)|}1,2">;
++def err_defaulted_comparison_not_friend : Error<
++ "%sub{select_defaulted_comparison_kind}0 is not a friend of"
++ " %select{|incomplete class }1%2">;
+ def err_defaulted_comparison_non_const : Error<
+ "defaulted member %sub{select_defaulted_comparison_kind}0 must be "
+ "const-qualified">;
+@@ -9512,6 +9519,9 @@ def err_os_log_argument_too_big : Error<
"os_log() argument %0 is too big (%1 bytes, max %2)">;
def warn_os_log_format_narg : Error<
"os_log() '%%n' format specifier is not allowed">, DefaultError;
blob - /dev/null
blob + 17dcb42ea75eda7d06441295c601087de08fb85f (mode 644)
--- /dev/null
+++ devel/llvm/patches/patch-tools_clang_lib_Basic_TargetInfo_cpp
@@ -0,0 +1,14 @@
+- Our malloc(3) guarantees 16-byte alignment.
+
+Index: tools/clang/lib/Basic/TargetInfo.cpp
+--- tools/clang/lib/Basic/TargetInfo.cpp.orig
++++ tools/clang/lib/Basic/TargetInfo.cpp
+@@ -70,7 +70,7 @@ TargetInfo::TargetInfo(const llvm::Triple &T) : Target
+ // the alignment is 16 bytes on both 64-bit and 32-bit systems.
+ if (T.isGNUEnvironment() || T.isWindowsMSVCEnvironment() || T.isAndroid())
+ NewAlign = Triple.isArch64Bit() ? 128 : Triple.isArch32Bit() ? 64 : 0;
+- else if (T.isOSDarwin())
++ else if (T.isOSDarwin() || T.isOSOpenBSD())
+ NewAlign = 128;
+ else
+ NewAlign = 0; // Infer from basic type alignment.
blob - f5ab7385cf446241e0cd3a8c4473d383ff57ed70
blob + a968ab35c1403aef9a883c58541871a77fa60f45
--- devel/llvm/patches/patch-tools_clang_lib_Driver_ToolChains_Clang_cpp
+++ devel/llvm/patches/patch-tools_clang_lib_Driver_ToolChains_Clang_cpp
@@ -29,11 +29,33 @@
gain a slight advantage, but would avoid the variety of important runtime
checks our malloc(3) code does. In essence, the transforms performed are
considered "anti-mitigation".
+- Make -mbranch-protection=bti the default on OpenBSD.
+- On openbsd amd64, emit IBT endbr64 instructions by default (meaning,
+ -fcf-protection=branch is the default).
+- On openbsd amd64, the compiler has been found to generate some nasty jump
+ table variations (calculate address into %rax, jmp %rax) which is not
+ compatible with IBT endbr64. So we will have to disable jump tables by
+ default.
+- Turn on pointer-authentication on arm64 as well by default. This means
+ we effectively enable -mbranch-protection=standard on arm64 now.

Index: tools/clang/lib/Driver/ToolChains/Clang.cpp
--- tools/clang/lib/Driver/ToolChains/Clang.cpp.orig
+++ tools/clang/lib/Driver/ToolChains/Clang.cpp
-@@ -2489,6 +2489,11 @@ static void CollectArgsForIntegratedAssembler(Compilat
+@@ -1818,6 +1818,12 @@ void Clang::AddAArch64TargetArgs(const ArgList &Args,
+ Args.MakeArgString(Twine("-msign-return-address-key=") + Key));
+ if (IndirectBranches)
+ CmdArgs.push_back("-mbranch-target-enforce");
++ } else {
++ if (Triple.isOSOpenBSD()) {
++ CmdArgs.push_back("-msign-return-address=non-leaf");
++ CmdArgs.push_back("-msign-return-address-key=a_key");
++ CmdArgs.push_back("-mbranch-target-enforce");
++ }
+ }
+
+ // Handle -msve_vector_bits=<bits>
+@@ -2489,6 +2495,11 @@ static void CollectArgsForIntegratedAssembler(Compilat
CmdArgs.push_back("-soft-float");
continue;
}
@@ -45,7 +67,7 @@ Index: tools/clang/lib/Driver/ToolChains/Clang.cpp

MipsTargetFeature = llvm::StringSwitch<const char *>(Value)
.Case("-mips1", "+mips1")
-@@ -4943,9 +4948,12 @@ void Clang::ConstructJob(Compilation &C, const JobActi
+@@ -4943,9 +4954,12 @@ void Clang::ConstructJob(Compilation &C, const JobActi
OFastEnabled ? options::OPT_Ofast : options::OPT_fstrict_aliasing;
// We turn strict aliasing off by default if we're in CL mode, since MSVC
// doesn't do any TBAA.
@@ -60,7 +82,7 @@ Index: tools/clang/lib/Driver/ToolChains/Clang.cpp
CmdArgs.push_back("-relaxed-aliasing");
if (!Args.hasFlag(options::OPT_fstruct_path_tbaa,
options::OPT_fno_struct_path_tbaa))
-@@ -5868,7 +5876,8 @@ void Clang::ConstructJob(Compilation &C, const JobActi
+@@ -5868,7 +5882,8 @@ void Clang::ConstructJob(Compilation &C, const JobActi
options::OPT_fno_strict_overflow)) {
if (A->getOption().matches(options::OPT_fno_strict_overflow))
CmdArgs.push_back("-fwrapv");
@@ -70,7 +92,7 @@ Index: tools/clang/lib/Driver/ToolChains/Clang.cpp

if (Arg *A = Args.getLastArg(options::OPT_freroll_loops,
options::OPT_fno_reroll_loops))
-@@ -5888,7 +5897,48 @@ void Clang::ConstructJob(Compilation &C, const JobActi
+@@ -5888,7 +5903,48 @@ void Clang::ConstructJob(Compilation &C, const JobActi
options::OPT_mno_speculative_load_hardening, false))
CmdArgs.push_back(Args.MakeArgString("-mspeculative-load-hardening"));

@@ -120,7 +142,19 @@ Index: tools/clang/lib/Driver/ToolChains/Clang.cpp
RenderSCPOptions(TC, Args, CmdArgs);
RenderTrivialAutoVarInitOptions(D, TC, Args, CmdArgs);

-@@ -6445,6 +6495,18 @@ void Clang::ConstructJob(Compilation &C, const JobActi
+@@ -5961,6 +6017,11 @@ void Clang::ConstructJob(Compilation &C, const JobActi
+ if (Arg *A = Args.getLastArg(options::OPT_fcf_protection_EQ)) {
+ CmdArgs.push_back(
+ Args.MakeArgString(Twine("-fcf-protection=") + A->getValue()));
++ } else if (Triple.isOSOpenBSD() && Triple.getArch() == llvm::Triple::x86_64) {
++ // Emit IBT endbr64 instructions by default
++ CmdArgs.push_back("-fcf-protection=branch");
++ // jump-table can generate indirect jumps, which are not permitted
++ CmdArgs.push_back("-fno-jump-tables");
+ }
+
+ // Forward -f options with positive and negative forms; we translate these by
+@@ -6445,6 +6506,18 @@ void Clang::ConstructJob(Compilation &C, const JobActi
options::OPT_fno_rewrite_imports, false);
if (RewriteImports)
CmdArgs.push_back("-frewrite-imports");
blob - /dev/null
blob + 321f7c568ec6d810ace5609614b4530feedaede7 (mode 644)
--- /dev/null
+++ devel/llvm/patches/patch-tools_clang_lib_CodeGen_CodeGenModule_cpp
@@ -0,0 +1,14 @@
+- Downgrade riscv64-specific LTO error to a warning
+
+Index: tools/clang/lib/CodeGen/CodeGenModule.cpp
+--- tools/clang/lib/CodeGen/CodeGenModule.cpp.orig
++++ tools/clang/lib/CodeGen/CodeGenModule.cpp
+@@ -846,7 +846,7 @@ void CodeGenModule::EmitBackendOptionsMetadata(
+ break;
+ case llvm::Triple::riscv32:
+ case llvm::Triple::riscv64:
+- getModule().addModuleFlag(llvm::Module::Error, "SmallDataLimit",
++ getModule().addModuleFlag(llvm::Module::Warning, "SmallDataLimit",
+ CodeGenOpts.SmallDataLimit);
+ break;
+ }
blob - 379f36e54cb1a550ebf6962ced901f0fd278e9a2
blob + fd5cccc6503608734703f04d0621fa349cd92b75
--- devel/llvm/patches/patch-tools_clang_lib_Driver_ToolChains_OpenBSD_cpp
+++ devel/llvm/patches/patch-tools_clang_lib_Driver_ToolChains_OpenBSD_cpp
@@ -1,6 +1,7 @@
- Add support for building against libestdc++ from ports-gcc.
- Allow the compiler driver to link the libclang_rt.profile library.
- Use Component in OpenBSD::getCompilerRT to find libraries.
+- Enable kernel-address sanitizer for clang openbsd target

Index: tools/clang/lib/Driver/ToolChains/OpenBSD.cpp
--- tools/clang/lib/Driver/ToolChains/OpenBSD.cpp.orig
@@ -46,7 +47,18 @@ Index: tools/clang/lib/Driver/ToolChains/OpenBSD.cpp
}

if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
-@@ -301,17 +313,34 @@ void OpenBSD::AddCXXStdlibLibArgs(const ArgList &Args,
+@@ -247,6 +259,10 @@ SanitizerMask OpenBSD::getSupportedSanitizers() const
+ Res |= SanitizerKind::FuzzerNoLink;
+ }
+
++ if (IsX86_64) {
++ Res |= SanitizerKind::KernelAddress;
++ }
++
+ return Res;
+ }
+
+@@ -301,17 +317,34 @@ void OpenBSD::AddCXXStdlibLibArgs(const ArgList &Args,
ArgStringList &CmdArgs) const {
bool Profiling = Args.hasArg(options::OPT_pg);

@@ -87,7 +99,7 @@ Index: tools/clang/lib/Driver/ToolChains/OpenBSD.cpp
}

Tool *OpenBSD::buildAssembler() const {
-@@ -321,3 +350,54 @@ Tool *OpenBSD::buildAssembler() const {
+@@ -321,3 +354,54 @@ Tool *OpenBSD::buildAssembler() const {
Tool *OpenBSD::buildLinker() const { return new tools::openbsd::Linker(*this); }

bool OpenBSD::HasNativeLLVMSupport() const { return true; }
blob - /dev/null
blob + 82f63c7cb278056de229d5defdc66fdcee55b63e (mode 644)
--- /dev/null
+++ devel/llvm/patches/patch-tools_clang_lib_Driver_Driver_cpp
@@ -0,0 +1,74 @@
+- Report versioned lib.so in cc --print-file-name given short name
+
+Index: tools/clang/lib/Driver/Driver.cpp
+--- tools/clang/lib/Driver/Driver.cpp.orig
++++ tools/clang/lib/Driver/Driver.cpp
+@@ -5089,7 +5089,50 @@ const char *Driver::GetNamedOutputPath(Compilation &C,
+ }
+ }
+
++
++namespace {
++static Optional<std::string> findFile(StringRef path1, const Twine &path2) {
++ SmallString<128> s;
++ llvm::sys::path::append(s, path1, path2);
++
++ if (llvm::sys::fs::exists(s))
++ return std::string(s);
++ return None;
++}
++
++// Must be in sync with findMajMinShlib in lld/ELF/DriverUtils.cpp.
++llvm::Optional<std::string> findMajMinShlib(StringRef dir, const Twine& libNameSo) {
++ // Handle OpenBSD-style maj/min shlib scheme
++ llvm::SmallString<128> Scratch;
++ const StringRef LibName = (libNameSo + ".").toStringRef(Scratch);
++ int MaxMaj = -1, MaxMin = -1;
++ std::error_code EC;
++ for (llvm::sys::fs::directory_iterator LI(dir, EC), LE;
++ LI != LE; LI = LI.increment(EC)) {
++ StringRef FilePath = LI->path();
++ StringRef FileName = llvm::sys::path::filename(FilePath);
++ if (!(FileName.startswith(LibName)))
++ continue;
++ std::pair<StringRef, StringRef> MajMin =
++ FileName.substr(LibName.size()).split('.');
++ int Maj, Min;
++ if (MajMin.first.getAsInteger(10, Maj) || Maj < 0)
++ continue;
++ if (MajMin.second.getAsInteger(10, Min) || Min < 0)
++ continue;
++ if (Maj > MaxMaj)
++ MaxMaj = Maj, MaxMin = Min;
++ if (MaxMaj == Maj && Min > MaxMin)
++ MaxMin = Min;
++ }
++ if (MaxMaj >= 0)
++ return findFile(dir, LibName + Twine(MaxMaj) + "." + Twine(MaxMin));
++ return None;
++}
++} // namespace
++
+ std::string Driver::GetFilePath(StringRef Name, const ToolChain &TC) const {
++ const bool lookForLibDotSo = Name.startswith("lib") && Name.endswith(".so");
+ // Search for Name in a list of paths.
+ auto SearchPaths = [&](const llvm::SmallVectorImpl<std::string> &P)
+ -> llvm::Optional<std::string> {
+@@ -5099,9 +5142,14 @@ std::string Driver::GetFilePath(StringRef Name, const
+ if (Dir.empty())
+ continue;
+ SmallString<128> P(Dir[0] == '=' ? SysRoot + Dir.substr(1) : Dir);
+- llvm::sys::path::append(P, Name);
+- if (llvm::sys::fs::exists(Twine(P)))
+- return std::string(P);
++ if (!lookForLibDotSo) {
++ llvm::sys::path::append(P, Name);
++ if (llvm::sys::fs::exists(Twine(P)))
++ return std::string(P);
++ } else {
++ if (auto s = findMajMinShlib(P, Name))
++ return std::string(*s);
++ }
+ }
+ return None;
+ };
blob - d0b4fbdb1f8ba0e9069cc5be5dcf15d4af2ed491
blob + 413963e6a9c2d022e7c5a7f512328425f56dcd6c
--- devel/llvm/patches/patch-tools_clang_lib_Driver_ToolChains_OpenBSD_h
+++ devel/llvm/patches/patch-tools_clang_lib_Driver_ToolChains_OpenBSD_h
@@ -1,10 +1,11 @@
- Add support for building against libestdc++ from ports-gcc.
-- Make clang emit the proper path to our libcompiler_rt.a when asked to.
+- Enable unwind tables on all clang architectures.
+- Arm is not ready for unwinding yet. Disable unwind info generation for now.

Index: tools/clang/lib/Driver/ToolChains/OpenBSD.h
--- tools/clang/lib/Driver/ToolChains/OpenBSD.h.orig
+++ tools/clang/lib/Driver/ToolChains/OpenBSD.h
-@@ -77,6 +77,11 @@ class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic
+@@ -77,8 +77,22 @@ class LLVM_LIBRARY_VISIBILITY OpenBSD : public Generic
void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) const override;

@@ -15,4 +16,15 @@ Index: tools/clang/lib/Driver/ToolChains/OpenBSD.h
+
std::string getCompilerRT(const llvm::opt::ArgList &Args, StringRef Component,
FileType Type = ToolChain::FT_Static) const override;
++
++ bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override {
++ switch (getArch()) {
++ case llvm::Triple::arm:
++ return false;
++ default:
++ return true;
++ }
++ }

+ LangOptions::StackProtectorMode
+ GetDefaultStackProtectorLevel(bool KernelOrKext) const override {
blob - db7ffd44cff1d09bcae16ad134afa5e2deaeb117
blob + 81df6650aa21862d78d344a5c645f700f666b276
--- devel/llvm/patches/patch-tools_lld_ELF_Config_h
+++ devel/llvm/patches/patch-tools_lld_ELF_Config_h
@@ -1,9 +1,19 @@
- XXX no comment
+- Implement support for PT_OPENBSD_NOBTCFI in lld(1). This can be set using
+ the -z nobtcfi option.

Index: tools/lld/ELF/Config.h
--- tools/lld/ELF/Config.h.orig
+++ tools/lld/ELF/Config.h
-@@ -266,8 +266,13 @@ struct Configuration {
+@@ -236,6 +236,7 @@ struct Configuration {
+ bool zInitfirst;
+ bool zInterpose;
+ bool zKeepTextSectionPrefix;
++ bool zNoBtCfi;
+ bool zNodefaultlib;
+ bool zNodelete;
+ bool zNodlopen;
+@@ -266,8 +267,13 @@ struct Configuration {
ELFKind ekind = ELFNoneKind;
uint16_t emachine = llvm::ELF::EM_NONE;
llvm::Optional<uint64_t> imageBase;
blob - 0a8f886ae5c779b4dd980d9846f92911147c8a09
blob + 7795edac2a243a00812b899c8ab057e57ded9028
--- devel/llvm/patches/patch-tools_lld_ELF_DriverUtils_cpp
+++ devel/llvm/patches/patch-tools_lld_ELF_DriverUtils_cpp
@@ -1,9 +1,46 @@
-Handle the OpenBSD-style major/minor shared library version scheme.
+- Handle the OpenBSD-style major/minor shared library version scheme.
+- Report versioned lib.so in cc --print-file-name given short name

Index: tools/lld/ELF/DriverUtils.cpp
--- tools/lld/ELF/DriverUtils.cpp.orig
+++ tools/lld/ELF/DriverUtils.cpp
-@@ -234,9 +234,36 @@ Optional<std::string> elf::findFromSearchPaths(StringR
+@@ -230,13 +230,48 @@ Optional<std::string> elf::findFromSearchPaths(StringR
+ return None;
+ }
+
++namespace {
++// Must be in sync with findMajMinShlib in clang/lib/Driver/Driver.cpp.
++llvm::Optional<std::string> findMajMinShlib(StringRef dir, const Twine& libNameSo) {
++ // Handle OpenBSD-style maj/min shlib scheme
++ llvm::SmallString<128> Scratch;
++ const StringRef LibName = (libNameSo + ".").toStringRef(Scratch);
++ int MaxMaj = -1, MaxMin = -1;
++ std::error_code EC;
++ for (llvm::sys::fs::directory_iterator LI(dir, EC), LE;
++ LI != LE; LI = LI.increment(EC)) {
++ StringRef FilePath = LI->path();
++ StringRef FileName = llvm::sys::path::filename(FilePath);
++ if (!(FileName.startswith(LibName)))
++ continue;
++ std::pair<StringRef, StringRef> MajMin =
++ FileName.substr(LibName.size()).split('.');
++ int Maj, Min;
++ if (MajMin.first.getAsInteger(10, Maj) || Maj < 0)
++ continue;
++ if (MajMin.second.getAsInteger(10, Min) || Min < 0)
++ continue;
++ if (Maj > MaxMaj)
++ MaxMaj = Maj, MaxMin = Min;
++ if (MaxMaj == Maj && Min > MaxMin)
++ MaxMin = Min;
++ }
++ if (MaxMaj >= 0)
++ return findFile(dir, LibName + Twine(MaxMaj) + "." + Twine(MaxMin));
++ return None;
++}
++} // namespace
++
+ // This is for -l<basename>. We'll look for lib<basename>.so or lib<basename>.a from
// search paths.
Optional<std::string> elf::searchLibraryBaseName(StringRef name) {
for (StringRef dir : config->searchPaths) {
@@ -11,32 +48,8 @@ Index: tools/lld/ELF/DriverUtils.cpp
+ if (!config->isStatic) {
if (Optional<std::string> s = findFile(dir, "lib" + name + ".so"))
return s;
-+
-+ // Handle OpenBSD-style maj/min shlib scheme
-+ llvm::SmallString<128> Scratch;
-+ const StringRef LibName = ("lib" + name + ".so.").toStringRef(Scratch);
-+ int MaxMaj = -1, MaxMin = -1;
-+ std::error_code EC;
-+ for (fs::directory_iterator LI(dir, EC), LE;
-+ LI != LE; LI = LI.increment(EC)) {
-+ StringRef FilePath = LI->path();
-+ StringRef FileName = path::filename(FilePath);
-+ if (!(FileName.startswith(LibName)))
-+ continue;
-+ std::pair<StringRef, StringRef> MajMin =
-+ FileName.substr(LibName.size()).split('.');
-+ int Maj, Min;
-+ if (MajMin.first.getAsInteger(10, Maj) || Maj < 0)
-+ continue;
-+ if (MajMin.second.getAsInteger(10, Min) || Min < 0)
-+ continue;
-+ if (Maj > MaxMaj)
-+ MaxMaj = Maj, MaxMin = Min;
-+ if (MaxMaj == Maj && Min > MaxMin)
-+ MaxMin = Min;
-+ }
-+ if (MaxMaj >= 0)
-+ return findFile(dir, LibName + Twine(MaxMaj) + "." + Twine(MaxMin));
++ if (Optional<std::string> s = findMajMinShlib(dir, "lib" + name + ".so"))
++ return s;
+ }
if (Optional<std::string> s = findFile(dir, "lib" + name + ".a"))
return s;
blob - 8eb56cfd7c258a1f2abcc422c2ef54ada21c44e3
blob + a4000fc8f7038c7c7a6d69cdfddc29da86abbc90
--- devel/llvm/patches/patch-tools_lld_ELF_Driver_cpp
+++ devel/llvm/patches/patch-tools_lld_ELF_Driver_cpp
@@ -1,12 +1,47 @@
- enable retpoline by default
-- allow-shlib-undefined by default
-- anable PIE by default.
+- enable PIE by default.
+- arm64 and riscv64 can now do --execute-only by default
+- enable --exec-only as default on AMD64
+- Make --execute-only the default on powerpc64.
+- Permit the --exec-only option on i386 also.
+- make --execute-only the default on powerpc
+- default sparc64 ld.lld to --execute-only
+- switch mips64 ld.lld to execute-only
+- Implement support for PT_OPENBSD_NOBTCFI in lld(1). This can be set using
+ the -z nobtcfi option.

-
Index: tools/lld/ELF/Driver.cpp
--- tools/lld/ELF/Driver.cpp.orig
+++ tools/lld/ELF/Driver.cpp
-@@ -455,6 +455,7 @@ static bool isKnownZFlag(StringRef s) {
+@@ -358,8 +358,19 @@ static void checkOptions() {
+ }
+
+ if (config->executeOnly) {
+- if (config->emachine != EM_AARCH64)
+- error("-execute-only is only supported on AArch64 targets");
++ switch (config->emachine) {
++ case EM_386:
++ case EM_AARCH64:
++ case EM_MIPS:
++ case EM_PPC:
++ case EM_PPC64:
++ case EM_RISCV:
++ case EM_SPARCV9:
++ case EM_X86_64:
++ break;
++ default:
++ error("-execute-only is not supported on this target");
++ }
+
+ if (config->singleRoRx && !script->hasSectionsCommand)
+ error("-execute-only and -no-rosegment cannot be used together");
+@@ -451,10 +462,12 @@ static bool isKnownZFlag(StringRef s) {
+ s == "initfirst" || s == "interpose" ||
+ s == "keep-text-section-prefix" || s == "lazy" || s == "muldefs" ||
+ s == "separate-code" || s == "separate-loadable-segments" ||
+- s == "start-stop-gc" || s == "nocombreloc" || s == "nocopyreloc" ||
++ s == "start-stop-gc" || s == "nobtcfi" ||
++ s == "nocombreloc" || s == "nocopyreloc" ||
s == "nodefaultlib" || s == "nodelete" || s == "nodlopen" ||
s == "noexecstack" || s == "nognustack" ||
s == "nokeep-text-section-prefix" || s == "norelro" ||
@@ -14,16 +49,16 @@ Index: tools/lld/ELF/Driver.cpp
s == "noseparate-code" || s == "nostart-stop-gc" || s == "notext" ||
s == "now" || s == "origin" || s == "pac-plt" || s == "rel" ||
s == "rela" || s == "relro" || s == "retpolineplt" ||
-@@ -598,7 +599,7 @@ static void setUnresolvedSymbolPolicy(opt::InputArgLis
- : UnresolvedPolicy::Warn;
- // -shared implies -unresolved-symbols=ignore-all because missing
- // symbols are likely to be resolved at runtime.
-- bool diagRegular = !config->shared, diagShlib = !config->shared;
-+ bool diagRegular = !config->shared, diagShlib = false;
+@@ -1045,8 +1058,6 @@ static void readConfigs(opt::InputArgList &args) {
+ errorHandler().errorHandlingScript =
+ args.getLastArgValue(OPT_error_handling_script);

- for (const opt::Arg *arg : args) {
- switch (arg->getOption().getID()) {
-@@ -1064,7 +1065,8 @@ static void readConfigs(opt::InputArgList &args) {
+- config->executeOnly =
+- args.hasFlag(OPT_execute_only, OPT_no_execute_only, false);
+ config->exportDynamic =
+ args.hasFlag(OPT_export_dynamic, OPT_no_export_dynamic, false);
+ config->filterList = args::getStrings(args, OPT_filter);
+@@ -1064,7 +1075,8 @@ static void readConfigs(opt::InputArgList &args) {
config->ignoreDataAddressEquality =
args.hasArg(OPT_ignore_data_address_equality);
config->ignoreFunctionAddressEquality =
@@ -33,7 +68,7 @@ Index: tools/lld/ELF/Driver.cpp
config->init = args.getLastArgValue(OPT_init, "_init");
config->ltoAAPipeline = args.getLastArgValue(OPT_lto_aa_pipeline);
config->ltoCSProfileGenerate = args.hasArg(OPT_lto_cs_profile_generate);
-@@ -1118,7 +1120,12 @@ static void readConfigs(opt::InputArgList &args) {
+@@ -1118,7 +1130,12 @@ static void readConfigs(opt::InputArgList &args) {
config->optimize = args::getInteger(args, OPT_O, 1);
config->orphanHandling = getOrphanHandling(args);
config->outputFile = args.getLastArgValue(OPT_o);
@@ -46,7 +81,15 @@ Index: tools/lld/ELF/Driver.cpp
config->printIcfSections =
args.hasFlag(OPT_print_icf_sections, OPT_no_print_icf_sections, false);
config->printGcSections =
-@@ -1188,7 +1195,11 @@ static void readConfigs(opt::InputArgList &args) {
+@@ -1181,6 +1198,7 @@ static void readConfigs(opt::InputArgList &args) {
+ config->zInterpose = hasZOption(args, "interpose");
+ config->zKeepTextSectionPrefix = getZFlag(
+ args, "keep-text-section-prefix", "nokeep-text-section-prefix", false);
++ config->zNoBtCfi = hasZOption(args, "nobtcfi");
+ config->zNodefaultlib = hasZOption(args, "nodefaultlib");
+ config->zNodelete = hasZOption(args, "nodelete");
+ config->zNodlopen = hasZOption(args, "nodlopen");
+@@ -1188,7 +1206,11 @@ static void readConfigs(opt::InputArgList &args) {
config->zOrigin = hasZOption(args, "origin");
config->zPacPlt = hasZOption(args, "pac-plt");
config->zRelro = getZFlag(args, "relro", "norelro", true);
@@ -59,16 +102,40 @@ Index: tools/lld/ELF/Driver.cpp
config->zRodynamic = hasZOption(args, "rodynamic");
config->zSeparate = getZSeparate(args);
config->zShstk = hasZOption(args, "shstk");
-@@ -1596,7 +1607,7 @@ void LinkerDriver::inferMachineType() {
+@@ -1459,6 +1481,23 @@ static void setConfigs(opt::InputArgList &args) {
+ args.hasFlag(OPT_toc_optimize, OPT_no_toc_optimize, m == EM_PPC64);
+ config->pcRelOptimize =
+ args.hasFlag(OPT_pcrel_optimize, OPT_no_pcrel_optimize, m == EM_PPC64);
++
++ config->executeOnly = false;
++#ifdef __OpenBSD__
++ switch (m) {
++ case EM_AARCH64:
++ case EM_MIPS:
++ case EM_PPC:
++ case EM_PPC64:
++ case EM_RISCV:
++ case EM_SPARCV9:
++ case EM_X86_64:
++ config->executeOnly = true;
++ break;
++ }
++

No comments:

Post a Comment