[PATCH] D43730: [ELF/COFF] Rename Strings.h to support case-insensative file systems
Rafael Avila de Espindola via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 26 09:52:24 PST 2018
What strings.h is it conflicting with?
We normally build lld on Windows and OS X which have case insensitive file
systems.
Cheers,
Rafael
Hagai Cohen via Phabricator via llvm-commits
<llvm-commits at lists.llvm.org> writes:
> DxCx created this revision.
> Herald added subscribers: llvm-commits, arichardson, javed.absar, mgorny, emaste.
>
> Hey,
>
> I'm trying to compile lld which it's sources are on shared storage network,
> unfortunately this shared resource is case-insensitive,
> Then in code, there is #include <strings.h> which actually resolves into local Strings.h file.
>
> So, this patch, will rename Strings.h to ELF/COFFString.h so the tree will be compatible with case-insensitive file system. after that resolving works just fine and lld is compiled and usable.
>
>
> Repository:
> rLLD LLVM Linker
>
> https://reviews.llvm.org/D43730
>
> Files:
> COFF/CMakeLists.txt
> COFF/COFFStrings.cpp
> COFF/COFFStrings.h
> COFF/Strings.cpp
> COFF/Strings.h
> COFF/Symbols.cpp
> ELF/AArch64ErrataFix.cpp
> ELF/CMakeLists.txt
> ELF/Driver.cpp
> ELF/ELFStrings.cpp
> ELF/ELFStrings.h
> ELF/EhFrame.cpp
> ELF/LinkerScript.cpp
> ELF/LinkerScript.h
> ELF/MapFile.cpp
> ELF/MarkLive.cpp
> ELF/OutputSections.cpp
> ELF/Relocations.cpp
> ELF/Strings.cpp
> ELF/Strings.h
> ELF/SymbolTable.h
> ELF/Symbols.h
> ELF/SyntheticSections.cpp
> ELF/Writer.cpp
>
> Index: ELF/Writer.cpp
> ===================================================================
> --- ELF/Writer.cpp
> +++ ELF/Writer.cpp
> @@ -15,7 +15,7 @@
> #include "MapFile.h"
> #include "OutputSections.h"
> #include "Relocations.h"
> -#include "Strings.h"
> +#include "ELFStrings.h"
> #include "SymbolTable.h"
> #include "Symbols.h"
> #include "SyntheticSections.h"
> Index: ELF/SyntheticSections.cpp
> ===================================================================
> --- ELF/SyntheticSections.cpp
> +++ ELF/SyntheticSections.cpp
> @@ -20,7 +20,7 @@
> #include "InputFiles.h"
> #include "LinkerScript.h"
> #include "OutputSections.h"
> -#include "Strings.h"
> +#include "ELFStrings.h"
> #include "SymbolTable.h"
> #include "Symbols.h"
> #include "Target.h"
> Index: ELF/Symbols.h
> ===================================================================
> --- ELF/Symbols.h
> +++ ELF/Symbols.h
> @@ -16,7 +16,7 @@
> #define LLD_ELF_SYMBOLS_H
>
> #include "InputSection.h"
> -#include "Strings.h"
> +#include "ELFStrings.h"
> #include "lld/Common/LLVM.h"
> #include "llvm/Object/Archive.h"
> #include "llvm/Object/ELF.h"
> Index: ELF/SymbolTable.h
> ===================================================================
> --- ELF/SymbolTable.h
> +++ ELF/SymbolTable.h
> @@ -12,7 +12,7 @@
>
> #include "InputFiles.h"
> #include "LTO.h"
> -#include "Strings.h"
> +#include "ELFStrings.h"
> #include "llvm/ADT/CachedHashString.h"
> #include "llvm/ADT/DenseMap.h"
>
> Index: ELF/Strings.h
> ===================================================================
> --- ELF/Strings.h
> +++ /dev/null
> @@ -1,75 +0,0 @@
> -//===- Strings.h ------------------------------------------------*- C++ -*-===//
> -//
> -// The LLVM Linker
> -//
> -// This file is distributed under the University of Illinois Open Source
> -// License. See LICENSE.TXT for details.
> -//
> -//===----------------------------------------------------------------------===//
> -
> -#ifndef LLD_ELF_STRINGS_H
> -#define LLD_ELF_STRINGS_H
> -
> -#include "lld/Common/LLVM.h"
> -#include "llvm/ADT/ArrayRef.h"
> -#include "llvm/ADT/BitVector.h"
> -#include "llvm/ADT/Optional.h"
> -#include "llvm/ADT/StringRef.h"
> -#include "llvm/Support/GlobPattern.h"
> -#include <vector>
> -
> -namespace lld {
> -namespace elf {
> -
> -std::vector<uint8_t> parseHex(StringRef S);
> -bool isValidCIdentifier(StringRef S);
> -
> -// This is a lazy version of StringRef. String size is computed lazily
> -// when it is needed. It is more efficient than StringRef to instantiate
> -// if you have a string whose size is unknown.
> -//
> -// ELF string tables contain a lot of null-terminated strings.
> -// Most of them are not necessary for the linker because they are names
> -// of local symbols and the linker doesn't use local symbol names for
> -// name resolution. So, we use this class to represents strings read
> -// from string tables.
> -class StringRefZ {
> -public:
> - StringRefZ() : Start(nullptr), Size(0) {}
> - StringRefZ(const char *S, size_t Size) : Start(S), Size(Size) {}
> -
> - /*implicit*/ StringRefZ(const char *S) : Start(S), Size(-1) {}
> -
> - /*implicit*/ StringRefZ(llvm::StringRef S)
> - : Start(S.data()), Size(S.size()) {}
> -
> - operator llvm::StringRef() const {
> - if (Size == (size_t)-1)
> - Size = strlen(Start);
> - return {Start, Size};
> - }
> -
> -private:
> - const char *Start;
> - mutable size_t Size;
> -};
> -
> -// This class represents multiple glob patterns.
> -class StringMatcher {
> -public:
> - StringMatcher() = default;
> - explicit StringMatcher(ArrayRef<StringRef> Pat);
> -
> - bool match(StringRef S) const;
> -
> -private:
> - std::vector<llvm::GlobPattern> Patterns;
> -};
> -
> -inline ArrayRef<uint8_t> toArrayRef(StringRef S) {
> - return {(const uint8_t *)S.data(), S.size()};
> -}
> -} // namespace elf
> -} // namespace lld
> -
> -#endif
> Index: ELF/Strings.cpp
> ===================================================================
> --- ELF/Strings.cpp
> +++ /dev/null
> @@ -1,60 +0,0 @@
> -//===- Strings.cpp -------------------------------------------------------===//
> -//
> -// The LLVM Linker
> -//
> -// This file is distributed under the University of Illinois Open Source
> -// License. See LICENSE.TXT for details.
> -//
> -//===----------------------------------------------------------------------===//
> -
> -#include "Strings.h"
> -#include "Config.h"
> -#include "lld/Common/ErrorHandler.h"
> -#include "llvm/ADT/Twine.h"
> -#include "llvm/Demangle/Demangle.h"
> -#include <algorithm>
> -#include <cstring>
> -
> -using namespace llvm;
> -using namespace lld;
> -using namespace lld::elf;
> -
> -StringMatcher::StringMatcher(ArrayRef<StringRef> Pat) {
> - for (StringRef S : Pat) {
> - Expected<GlobPattern> Pat = GlobPattern::create(S);
> - if (!Pat)
> - error(toString(Pat.takeError()));
> - else
> - Patterns.push_back(*Pat);
> - }
> -}
> -
> -bool StringMatcher::match(StringRef S) const {
> - for (const GlobPattern &Pat : Patterns)
> - if (Pat.match(S))
> - return true;
> - return false;
> -}
> -
> -// Converts a hex string (e.g. "deadbeef") to a vector.
> -std::vector<uint8_t> elf::parseHex(StringRef S) {
> - std::vector<uint8_t> Hex;
> - while (!S.empty()) {
> - StringRef B = S.substr(0, 2);
> - S = S.substr(2);
> - uint8_t H;
> - if (!to_integer(B, H, 16)) {
> - error("not a hexadecimal value: " + B);
> - return {};
> - }
> - Hex.push_back(H);
> - }
> - return Hex;
> -}
> -
> -// Returns true if S is valid as a C language identifier.
> -bool elf::isValidCIdentifier(StringRef S) {
> - return !S.empty() && (isAlpha(S[0]) || S[0] == '_') &&
> - std::all_of(S.begin() + 1, S.end(),
> - [](char C) { return C == '_' || isAlnum(C); });
> -}
> Index: ELF/Relocations.cpp
> ===================================================================
> --- ELF/Relocations.cpp
> +++ ELF/Relocations.cpp
> @@ -45,7 +45,7 @@
> #include "Config.h"
> #include "LinkerScript.h"
> #include "OutputSections.h"
> -#include "Strings.h"
> +#include "ELFStrings.h"
> #include "SymbolTable.h"
> #include "Symbols.h"
> #include "SyntheticSections.h"
> Index: ELF/OutputSections.cpp
> ===================================================================
> --- ELF/OutputSections.cpp
> +++ ELF/OutputSections.cpp
> @@ -10,7 +10,7 @@
> #include "OutputSections.h"
> #include "Config.h"
> #include "LinkerScript.h"
> -#include "Strings.h"
> +#include "ELFStrings.h"
> #include "SymbolTable.h"
> #include "SyntheticSections.h"
> #include "Target.h"
> Index: ELF/MarkLive.cpp
> ===================================================================
> --- ELF/MarkLive.cpp
> +++ ELF/MarkLive.cpp
> @@ -24,7 +24,7 @@
> #include "InputSection.h"
> #include "LinkerScript.h"
> #include "OutputSections.h"
> -#include "Strings.h"
> +#include "ELFStrings.h"
> #include "SymbolTable.h"
> #include "Symbols.h"
> #include "Target.h"
> Index: ELF/MapFile.cpp
> ===================================================================
> --- ELF/MapFile.cpp
> +++ ELF/MapFile.cpp
> @@ -23,7 +23,7 @@
> #include "InputFiles.h"
> #include "LinkerScript.h"
> #include "OutputSections.h"
> -#include "Strings.h"
> +#include "ELFStrings.h"
> #include "SymbolTable.h"
> #include "Symbols.h"
> #include "SyntheticSections.h"
> Index: ELF/LinkerScript.h
> ===================================================================
> --- ELF/LinkerScript.h
> +++ ELF/LinkerScript.h
> @@ -11,7 +11,7 @@
> #define LLD_ELF_LINKER_SCRIPT_H
>
> #include "Config.h"
> -#include "Strings.h"
> +#include "ELFStrings.h"
> #include "Writer.h"
> #include "lld/Common/LLVM.h"
> #include "llvm/ADT/ArrayRef.h"
> Index: ELF/LinkerScript.cpp
> ===================================================================
> --- ELF/LinkerScript.cpp
> +++ ELF/LinkerScript.cpp
> @@ -15,7 +15,7 @@
> #include "Config.h"
> #include "InputSection.h"
> #include "OutputSections.h"
> -#include "Strings.h"
> +#include "ELFStrings.h"
> #include "SymbolTable.h"
> #include "Symbols.h"
> #include "SyntheticSections.h"
> Index: ELF/EhFrame.cpp
> ===================================================================
> --- ELF/EhFrame.cpp
> +++ ELF/EhFrame.cpp
> @@ -20,7 +20,7 @@
> #include "Config.h"
> #include "InputSection.h"
> #include "Relocations.h"
> -#include "Strings.h"
> +#include "ELFStrings.h"
> #include "lld/Common/ErrorHandler.h"
> #include "llvm/BinaryFormat/Dwarf.h"
> #include "llvm/Object/ELF.h"
> Index: ELF/ELFStrings.h
> ===================================================================
> --- /dev/null
> +++ ELF/ELFStrings.h
> @@ -0,0 +1,75 @@
> +//===- ELFStrings.h ---------------------------------------------*- C++ -*-===//
> +//
> +// The LLVM Linker
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===----------------------------------------------------------------------===//
> +
> +#ifndef LLD_ELF_STRINGS_H
> +#define LLD_ELF_STRINGS_H
> +
> +#include "lld/Common/LLVM.h"
> +#include "llvm/ADT/ArrayRef.h"
> +#include "llvm/ADT/BitVector.h"
> +#include "llvm/ADT/Optional.h"
> +#include "llvm/ADT/StringRef.h"
> +#include "llvm/Support/GlobPattern.h"
> +#include <vector>
> +
> +namespace lld {
> +namespace elf {
> +
> +std::vector<uint8_t> parseHex(StringRef S);
> +bool isValidCIdentifier(StringRef S);
> +
> +// This is a lazy version of StringRef. String size is computed lazily
> +// when it is needed. It is more efficient than StringRef to instantiate
> +// if you have a string whose size is unknown.
> +//
> +// ELF string tables contain a lot of null-terminated strings.
> +// Most of them are not necessary for the linker because they are names
> +// of local symbols and the linker doesn't use local symbol names for
> +// name resolution. So, we use this class to represents strings read
> +// from string tables.
> +class StringRefZ {
> +public:
> + StringRefZ() : Start(nullptr), Size(0) {}
> + StringRefZ(const char *S, size_t Size) : Start(S), Size(Size) {}
> +
> + /*implicit*/ StringRefZ(const char *S) : Start(S), Size(-1) {}
> +
> + /*implicit*/ StringRefZ(llvm::StringRef S)
> + : Start(S.data()), Size(S.size()) {}
> +
> + operator llvm::StringRef() const {
> + if (Size == (size_t)-1)
> + Size = strlen(Start);
> + return {Start, Size};
> + }
> +
> +private:
> + const char *Start;
> + mutable size_t Size;
> +};
> +
> +// This class represents multiple glob patterns.
> +class StringMatcher {
> +public:
> + StringMatcher() = default;
> + explicit StringMatcher(ArrayRef<StringRef> Pat);
> +
> + bool match(StringRef S) const;
> +
> +private:
> + std::vector<llvm::GlobPattern> Patterns;
> +};
> +
> +inline ArrayRef<uint8_t> toArrayRef(StringRef S) {
> + return {(const uint8_t *)S.data(), S.size()};
> +}
> +} // namespace elf
> +} // namespace lld
> +
> +#endif
> Index: ELF/ELFStrings.cpp
> ===================================================================
> --- /dev/null
> +++ ELF/ELFStrings.cpp
> @@ -0,0 +1,60 @@
> +//===- Strings.cpp -------------------------------------------------------===//
> +//
> +// The LLVM Linker
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===----------------------------------------------------------------------===//
> +
> +#include "ELFStrings.h"
> +#include "Config.h"
> +#include "lld/Common/ErrorHandler.h"
> +#include "llvm/ADT/Twine.h"
> +#include "llvm/Demangle/Demangle.h"
> +#include <algorithm>
> +#include <cstring>
> +
> +using namespace llvm;
> +using namespace lld;
> +using namespace lld::elf;
> +
> +StringMatcher::StringMatcher(ArrayRef<StringRef> Pat) {
> + for (StringRef S : Pat) {
> + Expected<GlobPattern> Pat = GlobPattern::create(S);
> + if (!Pat)
> + error(toString(Pat.takeError()));
> + else
> + Patterns.push_back(*Pat);
> + }
> +}
> +
> +bool StringMatcher::match(StringRef S) const {
> + for (const GlobPattern &Pat : Patterns)
> + if (Pat.match(S))
> + return true;
> + return false;
> +}
> +
> +// Converts a hex string (e.g. "deadbeef") to a vector.
> +std::vector<uint8_t> elf::parseHex(StringRef S) {
> + std::vector<uint8_t> Hex;
> + while (!S.empty()) {
> + StringRef B = S.substr(0, 2);
> + S = S.substr(2);
> + uint8_t H;
> + if (!to_integer(B, H, 16)) {
> + error("not a hexadecimal value: " + B);
> + return {};
> + }
> + Hex.push_back(H);
> + }
> + return Hex;
> +}
> +
> +// Returns true if S is valid as a C language identifier.
> +bool elf::isValidCIdentifier(StringRef S) {
> + return !S.empty() && (isAlpha(S[0]) || S[0] == '_') &&
> + std::all_of(S.begin() + 1, S.end(),
> + [](char C) { return C == '_' || isAlnum(C); });
> +}
> Index: ELF/Driver.cpp
> ===================================================================
> --- ELF/Driver.cpp
> +++ ELF/Driver.cpp
> @@ -33,7 +33,7 @@
> #include "MarkLive.h"
> #include "OutputSections.h"
> #include "ScriptParser.h"
> -#include "Strings.h"
> +#include "ELFStrings.h"
> #include "SymbolTable.h"
> #include "Symbols.h"
> #include "SyntheticSections.h"
> Index: ELF/CMakeLists.txt
> ===================================================================
> --- ELF/CMakeLists.txt
> +++ ELF/CMakeLists.txt
> @@ -35,7 +35,7 @@
> Relocations.cpp
> ScriptLexer.cpp
> ScriptParser.cpp
> - Strings.cpp
> + ELFStrings.cpp
> SymbolTable.cpp
> Symbols.cpp
> SyntheticSections.cpp
> Index: ELF/AArch64ErrataFix.cpp
> ===================================================================
> --- ELF/AArch64ErrataFix.cpp
> +++ ELF/AArch64ErrataFix.cpp
> @@ -34,7 +34,7 @@
> #include "LinkerScript.h"
> #include "OutputSections.h"
> #include "Relocations.h"
> -#include "Strings.h"
> +#include "ELFStrings.h"
> #include "Symbols.h"
> #include "SyntheticSections.h"
> #include "Target.h"
> Index: COFF/Symbols.cpp
> ===================================================================
> --- COFF/Symbols.cpp
> +++ COFF/Symbols.cpp
> @@ -9,7 +9,7 @@
>
> #include "Symbols.h"
> #include "InputFiles.h"
> -#include "Strings.h"
> +#include "COFFStrings.h"
> #include "lld/Common/ErrorHandler.h"
> #include "lld/Common/Memory.h"
> #include "llvm/ADT/STLExtras.h"
> Index: COFF/Strings.h
> ===================================================================
> --- COFF/Strings.h
> +++ /dev/null
> @@ -1,23 +0,0 @@
> -//===- Strings.h ------------------------------------------------*- C++ -*-===//
> -//
> -// The LLVM Linker
> -//
> -// This file is distributed under the University of Illinois Open Source
> -// License. See LICENSE.TXT for details.
> -//
> -//===----------------------------------------------------------------------===//
> -
> -#ifndef LLD_COFF_STRINGS_H
> -#define LLD_COFF_STRINGS_H
> -
> -#include "llvm/ADT/Optional.h"
> -#include "llvm/ADT/StringRef.h"
> -#include <string>
> -
> -namespace lld {
> -namespace coff {
> -llvm::Optional<std::string> demangleMSVC(llvm::StringRef S);
> -}
> -}
> -
> -#endif
> Index: COFF/Strings.cpp
> ===================================================================
> --- COFF/Strings.cpp
> +++ /dev/null
> @@ -1,35 +0,0 @@
> -//===- Strings.cpp -------------------------------------------------------===//
> -//
> -// The LLVM Linker
> -//
> -// This file is distributed under the University of Illinois Open Source
> -// License. See LICENSE.TXT for details.
> -//
> -//===----------------------------------------------------------------------===//
> -
> -#include "Strings.h"
> -#include <mutex>
> -
> -#if defined(_MSC_VER)
> -#include <Windows.h>
> -#include <DbgHelp.h>
> -#pragma comment(lib, "dbghelp.lib")
> -#endif
> -
> -using namespace lld;
> -using namespace lld::coff;
> -using namespace llvm;
> -
> -Optional<std::string> coff::demangleMSVC(StringRef S) {
> -#if defined(_MSC_VER)
> - // UnDecorateSymbolName is not thread-safe, so we need a mutex.
> - static std::mutex Mu;
> - std::lock_guard<std::mutex> Lock(Mu);
> -
> - char Buf[4096];
> - if (S.startswith("?"))
> - if (size_t Len = UnDecorateSymbolName(S.str().c_str(), Buf, sizeof(Buf), 0))
> - return std::string(Buf, Len);
> -#endif
> - return None;
> -}
> Index: COFF/COFFStrings.h
> ===================================================================
> --- /dev/null
> +++ COFF/COFFStrings.h
> @@ -0,0 +1,23 @@
> +//===- COFFStrings.h --------------------------------------------*- C++ -*-===//
> +//
> +// The LLVM Linker
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===----------------------------------------------------------------------===//
> +
> +#ifndef LLD_COFF_STRINGS_H
> +#define LLD_COFF_STRINGS_H
> +
> +#include "llvm/ADT/Optional.h"
> +#include "llvm/ADT/StringRef.h"
> +#include <string>
> +
> +namespace lld {
> +namespace coff {
> +llvm::Optional<std::string> demangleMSVC(llvm::StringRef S);
> +}
> +}
> +
> +#endif
> Index: COFF/COFFStrings.cpp
> ===================================================================
> --- /dev/null
> +++ COFF/COFFStrings.cpp
> @@ -0,0 +1,35 @@
> +//===- Strings.cpp -------------------------------------------------------===//
> +//
> +// The LLVM Linker
> +//
> +// This file is distributed under the University of Illinois Open Source
> +// License. See LICENSE.TXT for details.
> +//
> +//===----------------------------------------------------------------------===//
> +
> +#include "COFFStrings.h"
> +#include <mutex>
> +
> +#if defined(_MSC_VER)
> +#include <Windows.h>
> +#include <DbgHelp.h>
> +#pragma comment(lib, "dbghelp.lib")
> +#endif
> +
> +using namespace lld;
> +using namespace lld::coff;
> +using namespace llvm;
> +
> +Optional<std::string> coff::demangleMSVC(StringRef S) {
> +#if defined(_MSC_VER)
> + // UnDecorateSymbolName is not thread-safe, so we need a mutex.
> + static std::mutex Mu;
> + std::lock_guard<std::mutex> Lock(Mu);
> +
> + char Buf[4096];
> + if (S.startswith("?"))
> + if (size_t Len = UnDecorateSymbolName(S.str().c_str(), Buf, sizeof(Buf), 0))
> + return std::string(Buf, Len);
> +#endif
> + return None;
> +}
> Index: COFF/CMakeLists.txt
> ===================================================================
> --- COFF/CMakeLists.txt
> +++ COFF/CMakeLists.txt
> @@ -18,7 +18,7 @@
> MarkLive.cpp
> MinGW.cpp
> PDB.cpp
> - Strings.cpp
> + COFFStrings.cpp
> SymbolTable.cpp
> Symbols.cpp
> Writer.cpp
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list