ports/devel/llvm/16/patches/patch-lld_ELF_Driver_cpp

156 lines
6 KiB
Text
Raw Normal View History

2023-09-08 05:21:37 +00:00
Index: lld/ELF/Driver.cpp
--- lld/ELF/Driver.cpp.orig
+++ lld/ELF/Driver.cpp
@@ -381,8 +381,19 @@ static void checkOptions() {
2023-08-16 22:26:55 +00:00
}
if (config->executeOnly) {
- if (config->emachine != EM_AARCH64)
2023-09-08 05:21:37 +00:00
- error("--execute-only is only supported on AArch64 targets");
2023-08-16 22:26:55 +00:00
+ 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)
2023-09-08 05:21:37 +00:00
error("--execute-only and --no-rosegment cannot be used together");
@@ -488,6 +499,7 @@ constexpr const char *knownZFlags[] = {
"keep-text-section-prefix",
"lazy",
"muldefs",
+ "nobtcfi",
"nocombreloc",
"nocopyreloc",
"nodefaultlib",
@@ -498,6 +510,7 @@ constexpr const char *knownZFlags[] = {
"nokeep-text-section-prefix",
"nopack-relative-relocs",
"norelro",
+ "noretpolineplt",
"noseparate-code",
"nostart-stop-gc",
"notext",
@@ -1105,8 +1118,6 @@ static void readConfigs(opt::InputArgList &args) {
2023-08-16 22:26:55 +00:00
errorHandler().errorHandlingScript =
args.getLastArgValue(OPT_error_handling_script);
- config->executeOnly =
- args.hasFlag(OPT_execute_only, OPT_no_execute_only, false);
config->exportDynamic =
2023-09-08 05:21:37 +00:00
args.hasFlag(OPT_export_dynamic, OPT_no_export_dynamic, false) ||
args.hasArg(OPT_shared);
@@ -1180,7 +1191,12 @@ static void readConfigs(opt::InputArgList &args) {
2023-08-16 22:26:55 +00:00
config->orphanHandling = getOrphanHandling(args);
config->outputFile = args.getLastArgValue(OPT_o);
2023-09-08 05:21:37 +00:00
config->packageMetadata = args.getLastArgValue(OPT_package_metadata);
2023-08-16 22:26:55 +00:00
+#ifdef __OpenBSD__
+ config->pie = args.hasFlag(OPT_pie, OPT_no_pie,
+ !args.hasArg(OPT_shared) && !args.hasArg(OPT_relocatable));
+#else
config->pie = args.hasFlag(OPT_pie, OPT_no_pie, false);
+#endif
config->printIcfSections =
args.hasFlag(OPT_print_icf_sections, OPT_no_print_icf_sections, false);
config->printGcSections =
2023-09-08 05:21:37 +00:00
@@ -1270,6 +1286,7 @@ static void readConfigs(opt::InputArgList &args) {
2023-08-16 22:26:55 +00:00
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");
2023-09-08 05:21:37 +00:00
@@ -1277,7 +1294,11 @@ static void readConfigs(opt::InputArgList &args) {
2023-08-16 22:26:55 +00:00
config->zOrigin = hasZOption(args, "origin");
config->zPacPlt = hasZOption(args, "pac-plt");
config->zRelro = getZFlag(args, "relro", "norelro", true);
- config->zRetpolineplt = hasZOption(args, "retpolineplt");
+#ifndef __OpenBSD__
+ config->zRetpolineplt = getZFlag(args, "retpolineplt", "noretpolineplt", false);
+#else
+ config->zRetpolineplt = getZFlag(args, "retpolineplt", "noretpolineplt", true);
+#endif
config->zRodynamic = hasZOption(args, "rodynamic");
config->zSeparate = getZSeparate(args);
config->zShstk = hasZOption(args, "shstk");
2023-09-08 05:21:37 +00:00
@@ -1582,6 +1603,23 @@ static void setConfigs(opt::InputArgList &args) {
2023-08-16 22:26:55 +00:00
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;
+ }
+#endif
+ config->executeOnly =
+ args.hasFlag(OPT_execute_only, OPT_no_execute_only, config->executeOnly);
}
2023-09-08 05:21:37 +00:00
static bool isFormatBinary(StringRef s) {
@@ -1721,7 +1759,7 @@ void LinkerDriver::inferMachineType() {
2023-08-16 22:26:55 +00:00
}
// Parse -z max-page-size=<value>. The default value is defined by
-// each target.
+// each target. Is set to 1 if given nmagic or omagic.
static uint64_t getMaxPageSize(opt::InputArgList &args) {
uint64_t val = args::getZOptionValue(args, OPT_z, "max-page-size",
target->defaultMaxPageSize);
2023-09-08 05:21:37 +00:00
@@ -1738,7 +1776,7 @@ static uint64_t getMaxPageSize(opt::InputArgList &args
2023-08-16 22:26:55 +00:00
}
// Parse -z common-page-size=<value>. The default value is defined by
-// each target.
+// each target. Is set to 1 if given nmagic or omagic.
static uint64_t getCommonPageSize(opt::InputArgList &args) {
uint64_t val = args::getZOptionValue(args, OPT_z, "common-page-size",
target->defaultCommonPageSize);
2023-09-08 05:21:37 +00:00
@@ -1757,6 +1795,16 @@ static uint64_t getCommonPageSize(opt::InputArgList &a
2023-08-16 22:26:55 +00:00
return val;
}
+// Parse -z max-page-size=<value>. The default value is defined by
+// each target.
+static uint64_t getRealMaxPageSize(opt::InputArgList &args) {
+ uint64_t val = args::getZOptionValue(args, OPT_z, "max-page-size",
+ target->defaultMaxPageSize);
+ if (!isPowerOf2_64(val))
+ error("max-page-size: value isn't a power of 2");
+ return val;
+}
+
2023-09-08 05:21:37 +00:00
// Parses --image-base option.
static std::optional<uint64_t> getImageBase(opt::InputArgList &args) {
2023-08-16 22:26:55 +00:00
// Because we are using "Config->maxPageSize" here, this function has to be
2023-09-08 05:21:37 +00:00
@@ -2784,6 +2832,11 @@ void LinkerDriver::link(opt::InputArgList &args) {
2023-08-16 22:26:55 +00:00
// optimizations such as DATA_SEGMENT_ALIGN in linker scripts. LLD's use of it
// is limited to writing trap instructions on the last executable segment.
config->commonPageSize = getCommonPageSize(args);
+ // textAlignPageSize is the alignment page size to use when aligning PT_LOAD
+ // sections. This is the same as maxPageSize except under -omagic, where data
+ // sections are non-aligned (maxPageSize set to 1) but text sections are aligned
+ // to the target page size.
+ config->textAlignPageSize = config->omagic ? getRealMaxPageSize(args) : config->maxPageSize;
config->imageBase = getImageBase(args);