[all-commits] [llvm/llvm-project] 69297c: [lld-macho] Don't include CommandFlags.h in Common...

Jez Ng via All-commits all-commits at lists.llvm.org
Wed Feb 16 17:05:29 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 69297cf639044acf48dd5d9b39b95c54dd50561d
      https://github.com/llvm/llvm-project/commit/69297cf639044acf48dd5d9b39b95c54dd50561d
  Author: Jez Ng <jezng at fb.com>
  Date:   2022-02-16 (Wed, 16 Feb 2022)

  Changed paths:
    M lld/Common/CommonLinkerContext.cpp
    M lld/ELF/Writer.cpp
    M lld/MachO/ICF.cpp
    M lld/include/lld/Common/CommonLinkerContext.h

  Log Message:
  -----------
  [lld-macho] Don't include CommandFlags.h in CommonLinkerContext.h

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`.

RegisterCodeGenFlags' ctor initializes a bunch of function-`static`
structures and does nothing else, so it should be fine to "initialize"
it as a temporary stack variable rather than as a file static.

Reviewed By: aganea

Differential Revision: https://reviews.llvm.org/D119913




More information about the All-commits mailing list