On Mon, Jan 28, 2019 at 03:38:38AM -0500, Brad Smith wrote:
> Merge in the other bits I had in the last diff I posted.
> 
> - Simplify a patch
> - Add -z interpose
> - 4 patches from patrick's tree for Clang/lld

And the i386 lld fix.


Index: Makefile
===================================================================
RCS file: /home/cvs/ports/devel/llvm/Makefile,v
retrieving revision 1.206
diff -u -p -u -p -r1.206 Makefile
--- Makefile    28 Jan 2019 06:27:28 -0000      1.206
+++ Makefile    28 Jan 2019 08:15:46 -0000
@@ -20,6 +20,7 @@ PKGSPEC-main =        llvm-=${LLVM_V}
 PKGNAME-main = llvm-${LLVM_V}
 PKGNAME-python =       py-llvm-${LLVM_V}
 PKGNAME-lldb = lldb-${LLVM_V}
+REVISION-main =        0
 CATEGORIES =   devel
 DISTFILES =    llvm-${LLVM_V}.src${EXTRACT_SUFX} \
                cfe-${LLVM_V}.src${EXTRACT_SUFX} \
Index: patches/patch-lib_MC_MCParser_AsmParser_cpp
===================================================================
RCS file: 
/home/cvs/ports/devel/llvm/patches/patch-lib_MC_MCParser_AsmParser_cpp,v
retrieving revision 1.5
diff -u -p -u -p -r1.5 patch-lib_MC_MCParser_AsmParser_cpp
--- patches/patch-lib_MC_MCParser_AsmParser_cpp 28 Jan 2019 06:27:28 -0000      
1.5
+++ patches/patch-lib_MC_MCParser_AsmParser_cpp 28 Jan 2019 08:08:50 -0000
@@ -11,22 +11,14 @@ a file directive.
 Index: lib/MC/MCParser/AsmParser.cpp
 --- lib/MC/MCParser/AsmParser.cpp.orig
 +++ lib/MC/MCParser/AsmParser.cpp
-@@ -858,6 +858,8 @@ bool AsmParser::Run(bool NoInitialTextSection, bool No
-   AsmCond StartingCondState = TheCondState;
-   SmallVector<AsmRewrite, 4> AsmStrRewrites;
- 
-+  StringRef Filename = getContext().getMainFileName();
-+
-   // If we are generating dwarf for assembly source files save the initial 
text
-   // section.  (Don't use enabledGenDwarfForAssembly() here, as we aren't
-   // emitting any actual debug info yet and haven't had a chance to parse any
-@@ -873,6 +875,9 @@ bool AsmParser::Run(bool NoInitialTextSection, bool No
-     assert(InsertResult && ".text section should not have debug info yet");
+@@ -874,6 +874,10 @@ bool AsmParser::Run(bool NoInitialTextSection, bool No
      (void)InsertResult;
    }
-+
+ 
++  StringRef Filename = getContext().getMainFileName();
 +  if (!Filename.empty() && (Filename.compare(StringRef("-")) != 0))
 +    Out.EmitFileDirective(Filename);
- 
++
    // While we have input, parse each statement.
    while (Lexer.isNot(AsmToken::Eof)) {
+     ParseStatementInfo Info(&AsmStrRewrites);
Index: patches/patch-tools_clang_lib_Driver_ToolChains_OpenBSD_cpp
===================================================================
RCS file: 
/home/cvs/ports/devel/llvm/patches/patch-tools_clang_lib_Driver_ToolChains_OpenBSD_cpp,v
retrieving revision 1.7
diff -u -p -u -p -r1.7 patch-tools_clang_lib_Driver_ToolChains_OpenBSD_cpp
--- patches/patch-tools_clang_lib_Driver_ToolChains_OpenBSD_cpp 28 Jan 2019 
06:27:28 -0000      1.7
+++ patches/patch-tools_clang_lib_Driver_ToolChains_OpenBSD_cpp 28 Jan 2019 
08:09:12 -0000
@@ -162,7 +162,7 @@ Index: tools/clang/lib/Driver/ToolChains
 +  case ToolChain::CST_Libcxx:
 +    CmdArgs.push_back(Profiling ? "-lc++_p" : "-lc++");
 +    CmdArgs.push_back(Profiling ? "-lc++abi_p" : "-lc++abi");
-+    CmdArgs.push_back("-lpthread");
++    CmdArgs.push_back(Profiling ? "-lpthread_p" : "-lpthread");
 +    break;
 +  case ToolChain::CST_Libstdcxx:
 +    CmdArgs.push_back("-lestdc++");
Index: patches/patch-tools_clang_lib_Frontend_InitHeaderSearch_cpp
===================================================================
RCS file: patches/patch-tools_clang_lib_Frontend_InitHeaderSearch_cpp
diff -N patches/patch-tools_clang_lib_Frontend_InitHeaderSearch_cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-tools_clang_lib_Frontend_InitHeaderSearch_cpp 28 Jan 2019 
08:06:37 -0000
@@ -0,0 +1,20 @@
+$OpenBSD$
+
+Index: tools/clang/lib/Frontend/InitHeaderSearch.cpp
+--- tools/clang/lib/Frontend/InitHeaderSearch.cpp.orig
++++ tools/clang/lib/Frontend/InitHeaderSearch.cpp
+@@ -431,14 +431,6 @@ void InitHeaderSearch::AddDefaultCPlusPlusIncludePaths
+   case llvm::Triple::DragonFly:
+     AddPath("/usr/include/c++/5.0", CXXSystem, false);
+     break;
+-  case llvm::Triple::OpenBSD: {
+-    std::string t = triple.getTriple();
+-    if (t.substr(0, 6) == "x86_64")
+-      t.replace(0, 6, "amd64");
+-    AddGnuCPlusPlusIncludePaths("/usr/include/g++",
+-                                t, "", "", triple);
+-    break;
+-  }
+   case llvm::Triple::Minix:
+     AddGnuCPlusPlusIncludePaths("/usr/gnu/include/c++/4.4.3",
+                                 "", "", "", triple);
Index: patches/patch-tools_lld_ELF_Config_h
===================================================================
RCS file: patches/patch-tools_lld_ELF_Config_h
diff -N patches/patch-tools_lld_ELF_Config_h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-tools_lld_ELF_Config_h        28 Jan 2019 08:09:41 -0000
@@ -0,0 +1,15 @@
+$OpenBSD$
+
+lld: add -z interpose support
+
+Index: tools/lld/ELF/Config.h
+--- tools/lld/ELF/Config.h.orig
++++ tools/lld/ELF/Config.h
+@@ -182,6 +182,7 @@ struct Configuration {
+   bool ZExecstack;
+   bool ZHazardplt;
+   bool ZInitfirst;
++  bool ZInterpose;
+   bool ZKeepTextSectionPrefix;
+   bool ZNodelete;
+   bool ZNodlopen;
Index: patches/patch-tools_lld_ELF_Driver_cpp
===================================================================
RCS file: /home/cvs/ports/devel/llvm/patches/patch-tools_lld_ELF_Driver_cpp,v
retrieving revision 1.11
diff -u -p -u -p -r1.11 patch-tools_lld_ELF_Driver_cpp
--- patches/patch-tools_lld_ELF_Driver_cpp      28 Jan 2019 06:27:28 -0000      
1.11
+++ patches/patch-tools_lld_ELF_Driver_cpp      28 Jan 2019 08:10:04 -0000
@@ -1,11 +1,24 @@
 $OpenBSD: patch-tools_lld_ELF_Driver_cpp,v 1.11 2019/01/28 06:27:28 jca Exp $
 
-Enable PIE by default.
+- Enable PIE by default.
+- lld: add -z interpose support
 
 Index: tools/lld/ELF/Driver.cpp
 --- tools/lld/ELF/Driver.cpp.orig
 +++ tools/lld/ELF/Driver.cpp
-@@ -794,7 +794,8 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args
+@@ -339,8 +339,9 @@ static bool getZFlag(opt::InputArgList &Args, StringRe
+ static bool isKnown(StringRef S) {
+   return S == "combreloc" || S == "copyreloc" || S == "defs" ||
+          S == "execstack" || S == "hazardplt" || S == "initfirst" ||
+-         S == "keep-text-section-prefix" || S == "lazy" || S == "muldefs" ||
+-         S == "nocombreloc" || S == "nocopyreloc" || S == "nodelete" ||
++         S == "interpose" || S == "keep-text-section-prefix" ||
++         S == "lazy" || S == "muldefs" || S == "nocombreloc" ||
++         S == "nocopyreloc" || S == "nodelete" ||
+          S == "nodlopen" || S == "noexecstack" ||
+          S == "nokeep-text-section-prefix" || S == "norelro" || S == "notext" 
||
+          S == "now" || S == "origin" || S == "relro" || S == "retpolineplt" ||
+@@ -794,7 +795,8 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args
    Config->Optimize = args::getInteger(Args, OPT_O, 1);
    Config->OrphanHandling = getOrphanHandling(Args);
    Config->OutputFile = Args.getLastArgValue(OPT_o);
@@ -15,3 +28,11 @@ Index: tools/lld/ELF/Driver.cpp
    Config->PrintIcfSections =
        Args.hasFlag(OPT_print_icf_sections, OPT_no_print_icf_sections, false);
    Config->PrintGcSections =
+@@ -844,6 +846,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args
+   Config->ZExecstack = getZFlag(Args, "execstack", "noexecstack", false);
+   Config->ZHazardplt = hasZOption(Args, "hazardplt");
+   Config->ZInitfirst = hasZOption(Args, "initfirst");
++  Config->ZInterpose = hasZOption(Args, "interpose");
+   Config->ZKeepTextSectionPrefix = getZFlag(
+       Args, "keep-text-section-prefix", "nokeep-text-section-prefix", false);
+   Config->ZNodelete = hasZOption(Args, "nodelete");
Index: patches/patch-tools_lld_ELF_LinkerScript_cpp
===================================================================
RCS file: patches/patch-tools_lld_ELF_LinkerScript_cpp
diff -N patches/patch-tools_lld_ELF_LinkerScript_cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ patches/patch-tools_lld_ELF_LinkerScript_cpp        28 Jan 2019 08:04:59 
-0000
@@ -0,0 +1,21 @@
+$OpenBSD$
+
+Index: tools/lld/ELF/LinkerScript.cpp
+--- tools/lld/ELF/LinkerScript.cpp.orig
++++ tools/lld/ELF/LinkerScript.cpp
+@@ -771,13 +771,13 @@ void LinkerScript::assignOffsets(OutputSection *Sec) {
+   if (Ctx->MemRegion)
+     Dot = Ctx->MemRegion->CurPos;
+ 
+-  switchTo(Sec);
+-
+   if (Sec->LMAExpr)
+     Ctx->LMAOffset = Sec->LMAExpr().getValue() - Dot;
+ 
+   if (MemoryRegion *MR = Sec->LMARegion)
+     Ctx->LMAOffset = MR->CurPos - Dot;
++
++  switchTo(Sec);
+ 
+   // If neither AT nor AT> is specified for an allocatable section, the linker
+   // will set the LMA such that the difference between VMA and LMA for the
Index: patches/patch-tools_lld_ELF_Options_td
===================================================================
RCS file: /home/cvs/ports/devel/llvm/patches/patch-tools_lld_ELF_Options_td,v
retrieving revision 1.2
diff -u -p -u -p -r1.2 patch-tools_lld_ELF_Options_td
--- patches/patch-tools_lld_ELF_Options_td      28 Jan 2019 06:27:28 -0000      
1.2
+++ patches/patch-tools_lld_ELF_Options_td      28 Jan 2019 08:10:31 -0000
@@ -5,7 +5,19 @@ $OpenBSD: patch-tools_lld_ELF_Options_td
 Index: tools/lld/ELF/Options.td
 --- tools/lld/ELF/Options.td.orig
 +++ tools/lld/ELF/Options.td
-@@ -386,6 +386,7 @@ def: Separate<["-"], "b">, Alias<format>, HelpText<"Al
+@@ -178,8 +178,9 @@ def icf_safe: F<"icf=safe">, HelpText<"Enable safe ide
+ 
+ def icf_none: F<"icf=none">, HelpText<"Disable identical code folding 
(default)">;
+ 
+-def ignore_function_address_equality: F<"ignore-function-address-equality">,
+-  HelpText<"lld can break the address equality of functions">;
++defm ignore_function_address_equality: B<"ignore-function-address-equality",
++  "lld can break the address equality of functions",
++  "lld cannot break the address equality of functions">;
+ 
+ def ignore_data_address_equality: F<"ignore-data-address-equality">,
+   HelpText<"lld can break the address equality of data">;
+@@ -386,6 +387,7 @@ def: Separate<["-"], "b">, Alias<format>, HelpText<"Al
  def: JoinedOrSeparate<["-"], "l">, Alias<library>, HelpText<"Alias for 
--library">;
  def: JoinedOrSeparate<["-"], "L">, Alias<library_path>, HelpText<"Alias for 
--library-path">;
  def: F<"no-pic-executable">, Alias<no_pie>, HelpText<"Alias for --no-pie">;
Index: patches/patch-tools_lld_ELF_Symbols_h
===================================================================
RCS file: /home/cvs/ports/devel/llvm/patches/patch-tools_lld_ELF_Symbols_h,v
retrieving revision 1.2
diff -u -p -u -p -r1.2 patch-tools_lld_ELF_Symbols_h
--- patches/patch-tools_lld_ELF_Symbols_h       28 Jan 2019 06:27:28 -0000      
1.2
+++ patches/patch-tools_lld_ELF_Symbols_h       28 Jan 2019 08:11:01 -0000
@@ -1,5 +1,8 @@
 $OpenBSD: patch-tools_lld_ELF_Symbols_h,v 1.2 2019/01/28 06:27:28 jca Exp $
 
+Generate __data_start symbol that marks the start of .data when __data_start
+is referenced from code being linked.
+
 Index: tools/lld/ELF/Symbols.h
 --- tools/lld/ELF/Symbols.h.orig
 +++ tools/lld/ELF/Symbols.h
Index: patches/patch-tools_lld_ELF_SyntheticSections_cpp
===================================================================
RCS file: 
/home/cvs/ports/devel/llvm/patches/patch-tools_lld_ELF_SyntheticSections_cpp,v
retrieving revision 1.9
diff -u -p -u -p -r1.9 patch-tools_lld_ELF_SyntheticSections_cpp
--- patches/patch-tools_lld_ELF_SyntheticSections_cpp   28 Jan 2019 06:27:28 
-0000      1.9
+++ patches/patch-tools_lld_ELF_SyntheticSections_cpp   28 Jan 2019 08:11:43 
-0000
@@ -1,16 +1,26 @@
 $OpenBSD: patch-tools_lld_ELF_SyntheticSections_cpp,v 1.9 2019/01/28 06:27:28 
jca Exp $
 
-When merging sections into the output, lld tries to adjust the alignment of
-the section to be at least as large as the entry size of the section.
-This causes a later check that validates the alignment to fail if the
-entry size isn't a power of two.  This happens when building some of the
-java support code in ports gcc.  Fix this by sticking to the original
-alignment if the entry size isn't a power of two.
+- lld: add -z interpose support
+- When merging sections into the output, lld tries to adjust the alignment of
+  the section to be at least as large as the entry size of the section.
+  This causes a later check that validates the alignment to fail if the
+  entry size isn't a power of two.  This happens when building some of the
+  java support code in ports gcc.  Fix this by sticking to the original
+  alignment if the entry size isn't a power of two.
 
 Index: tools/lld/ELF/SyntheticSections.cpp
 --- tools/lld/ELF/SyntheticSections.cpp.orig
 +++ tools/lld/ELF/SyntheticSections.cpp
-@@ -2935,7 +2935,9 @@ void elf::mergeSections() {
+@@ -1266,6 +1266,8 @@ template <class ELFT> void DynamicSection<ELFT>::final
+     DtFlags |= DF_SYMBOLIC;
+   if (Config->ZInitfirst)
+     DtFlags1 |= DF_1_INITFIRST;
++  if (Config->ZInterpose)
++    DtFlags1 |= DF_1_INTERPOSE;
+   if (Config->ZNodelete)
+     DtFlags1 |= DF_1_NODELETE;
+   if (Config->ZNodlopen)
+@@ -2935,7 +2937,9 @@ void elf::mergeSections() {
      }
  
      StringRef OutsecName = getOutputSectionName(MS);
Index: patches/patch-tools_lld_ELF_Writer_cpp
===================================================================
RCS file: /home/cvs/ports/devel/llvm/patches/patch-tools_lld_ELF_Writer_cpp,v
retrieving revision 1.9
diff -u -p -u -p -r1.9 patch-tools_lld_ELF_Writer_cpp
--- patches/patch-tools_lld_ELF_Writer_cpp      28 Jan 2019 06:27:28 -0000      
1.9
+++ patches/patch-tools_lld_ELF_Writer_cpp      28 Jan 2019 11:24:10 -0000
@@ -2,7 +2,10 @@ $OpenBSD: patch-tools_lld_ELF_Writer_cpp
 
 - Merge '.openbsd.randomdata.*' sections into a single '.openbsd.randomdata'
   section when linking, as we do when using ld from binutils.
+- Generate __data_start symbol that marks the start of .data when __data_start
+  is referenced from code being linked.
 - Put .got.plt in RELRO.
+- On i386, produce binaries that are compatible with our W^X implementation.
 
 Index: tools/lld/ELF/Writer.cpp
 --- tools/lld/ELF/Writer.cpp.orig
@@ -37,13 +40,37 @@ Index: tools/lld/ELF/Writer.cpp
  
    // .dynamic section contains data for the dynamic linker, and
    // there's no need to write to it at runtime, so it's better to put
-@@ -961,6 +967,9 @@ template <class ELFT> void Writer<ELFT>::setReservedSy
- 
+@@ -962,6 +968,9 @@ template <class ELFT> void Writer<ELFT>::setReservedSy
    if (ElfSym::Bss)
      ElfSym::Bss->Section = findSection(".bss");
-+
+ 
 +  if (ElfSym::Data)
 +    ElfSym::Data->Section = findSection(".data");
- 
++
    // Setup MIPS _gp_disp/__gnu_local_gp symbols which should
    // be equal to the _gp symbol's value.
+   if (ElfSym::MipsGp) {
+@@ -1937,6 +1946,23 @@ template <class ELFT> void Writer<ELFT>::fixSectionAli
+         return alignTo(Script->getDot(), Config->MaxPageSize);
+       };
+   };
++
++#ifdef __OpenBSD__
++  auto NXAlign = [](OutputSection *Cmd) {
++    if (Cmd && !Cmd->AddrExpr)
++      Cmd->AddrExpr = [=] {
++        return alignTo(Script->getDot(), 0x20000000);
++      };
++  };
++
++  PhdrEntry *firstRW = nullptr;
++  for (PhdrEntry *P : Phdrs)
++    if (P->p_type == PT_LOAD && (P->p_flags & PF_W))
++      firstRW = P;
++
++  if (Config->EMachine == EM_386 && firstRW)
++    NXAlign(firstRW->FirstSec);
++#endif
+ 
+   for (const PhdrEntry *P : Phdrs)
+     if (P->p_type == PT_LOAD && P->FirstSec)

Reply via email to