From 9814d151361a73477143304140696d4a94c0738f Mon Sep 17 00:00:00 2001 From: George Rimar Date: Wed, 25 Oct 2017 15:20:30 +0000 Subject: [PATCH] [ELF] - Implement --orphan-handling option. It is PR34946. Spec (http://man7.org/linux/man-pages/man1/ld.1.html) tells about --orphan-handling=MODE, option where MODE can be one of four: "place", "discard", "warn", "error". Currently we already report orphans when -verbose given, what becomes excessive with option implemented. Patch stops reporting orphans when -versbose is given, and support "place", "warn" and "error" modes. It is not yet clear that "discard" mode is useful so it is not supported. Differential revision: https://reviews.llvm.org/D39000 llvm-svn: 316583 --- lld/ELF/Config.h | 4 ++ lld/ELF/Driver.cpp | 12 ++++++ lld/ELF/LinkerScript.cpp | 9 +++- lld/ELF/Options.td | 3 ++ lld/test/ELF/linkerscript/orphan-report.s | 68 ++++++++++++++++++++----------- 5 files changed, 71 insertions(+), 25 deletions(-) diff --git a/lld/ELF/Config.h b/lld/ELF/Config.h index d753af7..8da6d4c 100644 --- a/lld/ELF/Config.h +++ b/lld/ELF/Config.h @@ -46,6 +46,9 @@ enum class StripPolicy { None, All, Debug }; // For --unresolved-symbols. enum class UnresolvedPolicy { ReportError, Warn, Ignore, IgnoreAll }; +// For --orphan-handling. +enum class OrphanHandlingPolicy { Place, Warn, Error }; + // For --sort-section and linkerscript sorting rules. enum class SortSectionPolicy { Default, None, Alignment, Name, Priority }; @@ -155,6 +158,7 @@ struct Configuration { bool ExitEarly; bool ZWxneeded; DiscardPolicy Discard; + OrphanHandlingPolicy OrphanHandling; SortSectionPolicy SortSection; StripPolicy Strip; UnresolvedPolicy UnresolvedSymbols; diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 73bc3c3..5ffc877 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -554,6 +554,17 @@ static SortSectionPolicy getSortSection(opt::InputArgList &Args) { return SortSectionPolicy::Default; } +static OrphanHandlingPolicy getOrphanHandling(opt::InputArgList &Args) { + StringRef S = Args.getLastArgValue(OPT_orphan_handling, "place"); + if (S == "warn") + return OrphanHandlingPolicy::Warn; + if (S == "error") + return OrphanHandlingPolicy::Error; + if (S != "place") + error("unknown --orphan-handling mode: " + S); + return OrphanHandlingPolicy::Place; +} + // Parse --build-id or --build-id=