[PATCH] D119913: [lld-macho] Make RegisterCodeFlags a file-scope static again

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 15 20:45:03 PST 2022


int3 created this revision.
int3 added reviewers: lld-macho, aganea, MaskRay.
int3 requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Main motivation: including `llvm/CodeGen/CommandFlags.h` in
`CommonLinkerContext.h` means that the declaration of `llvm::Reloc` is
visible in any file that includes `CommonLinkerContext.h`. Since our
cpp files have both `using namespace llvm` and `using namespace
lld::macho`, this results in conflicts with `lld::macho::Reloc`.

I suppose we could put `llvm::Reloc` into a nested namespace, but in general,
I think we should avoid transitively including too many header files in
a very widely used header like `CommonLinkerContext.h`.

So this diff undoes part of the change in D108850: [LLD] Remove global state in lldCommon <https://reviews.llvm.org/D108850> by making
`RegisterCodeGenFlags` a file static. RegisterCodeGenFlags' ctor
initializes a bunch of function-`static` structures, so hoisting the
struct into the LinkingContext shouldn't make a difference to LLD's
usability as a library -- it's still initializing a bunch of global
state. (I'm not sure whether `RegisterCodeGenFlags` itself needs to be
changed for full library-fication of LLD, though.)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119913

Files:
  lld/Common/TargetOptionsCommandFlags.cpp
  lld/include/lld/Common/CommonLinkerContext.h


Index: lld/include/lld/Common/CommonLinkerContext.h
===================================================================
--- lld/include/lld/Common/CommonLinkerContext.h
+++ lld/include/lld/Common/CommonLinkerContext.h
@@ -21,7 +21,6 @@
 
 #include "lld/Common/ErrorHandler.h"
 #include "lld/Common/Memory.h"
-#include "llvm/CodeGen/CommandFlags.h"
 #include "llvm/Support/StringSaver.h"
 
 namespace llvm {
@@ -42,9 +41,6 @@
   llvm::DenseMap<void *, SpecificAllocBase *> instances;
 
   ErrorHandler e;
-
-private:
-  llvm::codegen::RegisterCodeGenFlags cgf;
 };
 
 // Retrieve the global state. Currently only one state can exist per process,
Index: lld/Common/TargetOptionsCommandFlags.cpp
===================================================================
--- lld/Common/TargetOptionsCommandFlags.cpp
+++ lld/Common/TargetOptionsCommandFlags.cpp
@@ -10,6 +10,8 @@
 #include "llvm/CodeGen/CommandFlags.h"
 #include "llvm/Target/TargetOptions.h"
 
+static llvm::codegen::RegisterCodeGenFlags CGF;
+
 llvm::TargetOptions lld::initTargetOptionsFromCodeGenFlags() {
   return llvm::codegen::InitTargetOptionsFromCodeGenFlags(llvm::Triple());
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119913.409138.patch
Type: text/x-patch
Size: 1145 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220216/3c303a7c/attachment.bin>


More information about the llvm-commits mailing list