Skip to content

Commit 92da37b

Browse files
authored
[Object][NFC] Add extern template declarations needed by llvm-objdump (#109156)
These symbols are implicitly imported from the LLVM shared library by llvm-objdump on ELF like platforms, but for windows they need to be explicitly exported when LLVM is built as shared library. I also add visibility macros for XCOFFObjectFile::getExceptionEntries that can't automatically be added by clang tooling since it doesn't store the source locations for explicit function template instantiations.
1 parent 2c6e5ef commit 92da37b

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

llvm/include/llvm/Object/ELF.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/BinaryFormat/ELF.h"
2222
#include "llvm/Object/ELFTypes.h"
2323
#include "llvm/Object/Error.h"
24+
#include "llvm/Support/Compiler.h"
2425
#include "llvm/Support/DataExtractor.h"
2526
#include "llvm/Support/Error.h"
2627
#include <cassert>
@@ -1367,6 +1368,11 @@ inline uint32_t hashGnu(StringRef Name) {
13671368
return H;
13681369
}
13691370

1371+
extern template class LLVM_TEMPLATE_ABI llvm::object::ELFFile<ELF32LE>;
1372+
extern template class LLVM_TEMPLATE_ABI llvm::object::ELFFile<ELF32BE>;
1373+
extern template class LLVM_TEMPLATE_ABI llvm::object::ELFFile<ELF64LE>;
1374+
extern template class LLVM_TEMPLATE_ABI llvm::object::ELFFile<ELF64BE>;
1375+
13701376
} // end namespace object
13711377
} // end namespace llvm
13721378

llvm/include/llvm/Object/XCOFFObjectFile.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "llvm/ADT/iterator_range.h"
1919
#include "llvm/BinaryFormat/XCOFF.h"
2020
#include "llvm/Object/ObjectFile.h"
21+
#include "llvm/Support/Compiler.h"
2122
#include "llvm/Support/Endian.h"
2223
#include <limits>
2324

@@ -775,6 +776,13 @@ struct XCOFFSymbolEntry64 {
775776
uint8_t NumberOfAuxEntries;
776777
};
777778

779+
extern template LLVM_TEMPLATE_ABI Expected<ArrayRef<XCOFFRelocation32>>
780+
XCOFFObjectFile::relocations<XCOFFSectionHeader32, XCOFFRelocation32>(
781+
const XCOFFSectionHeader32 &Sec) const;
782+
extern template LLVM_TEMPLATE_ABI Expected<ArrayRef<XCOFFRelocation64>>
783+
XCOFFObjectFile::relocations<XCOFFSectionHeader64, XCOFFRelocation64>(
784+
const XCOFFSectionHeader64 &Sec) const;
785+
778786
class XCOFFSymbolRef : public SymbolRef {
779787
public:
780788
enum { NAME_IN_STR_TBL_MAGIC = 0x0 };

llvm/lib/Object/ELF.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "llvm/Object/ELF.h"
1010
#include "llvm/ADT/StringExtras.h"
1111
#include "llvm/BinaryFormat/ELF.h"
12+
#include "llvm/Support/Compiler.h"
1213
#include "llvm/Support/DataExtractor.h"
1314

1415
using namespace llvm;
@@ -980,7 +981,7 @@ ELFFile<ELFT>::getSectionAndRelocations(
980981
return SecToRelocMap;
981982
}
982983

983-
template class llvm::object::ELFFile<ELF32LE>;
984-
template class llvm::object::ELFFile<ELF32BE>;
985-
template class llvm::object::ELFFile<ELF64LE>;
986-
template class llvm::object::ELFFile<ELF64BE>;
984+
template class LLVM_EXPORT_TEMPLATE llvm::object::ELFFile<ELF32LE>;
985+
template class LLVM_EXPORT_TEMPLATE llvm::object::ELFFile<ELF32BE>;
986+
template class LLVM_EXPORT_TEMPLATE llvm::object::ELFFile<ELF64LE>;
987+
template class LLVM_EXPORT_TEMPLATE llvm::object::ELFFile<ELF64BE>;

llvm/lib/Object/XCOFFObjectFile.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "llvm/Object/XCOFFObjectFile.h"
1414
#include "llvm/ADT/StringSwitch.h"
15+
#include "llvm/Support/Compiler.h"
1516
#include "llvm/Support/DataExtractor.h"
1617
#include "llvm/TargetParser/SubtargetFeature.h"
1718
#include <cstddef>
@@ -1060,9 +1061,9 @@ Expected<ArrayRef<ExceptEnt>> XCOFFObjectFile::getExceptionEntries() const {
10601061
ExceptEntStart, ExceptEntStart + getSectionSize(DRI) / sizeof(ExceptEnt));
10611062
}
10621063

1063-
template Expected<ArrayRef<ExceptionSectionEntry32>>
1064+
template LLVM_EXPORT_TEMPLATE Expected<ArrayRef<ExceptionSectionEntry32>>
10641065
XCOFFObjectFile::getExceptionEntries() const;
1065-
template Expected<ArrayRef<ExceptionSectionEntry64>>
1066+
template LLVM_EXPORT_TEMPLATE Expected<ArrayRef<ExceptionSectionEntry64>>
10661067
XCOFFObjectFile::getExceptionEntries() const;
10671068

10681069
Expected<XCOFFStringTable>
@@ -1376,14 +1377,16 @@ template struct XCOFFSectionHeader<XCOFFSectionHeader64>;
13761377
template struct XCOFFRelocation<llvm::support::ubig32_t>;
13771378
template struct XCOFFRelocation<llvm::support::ubig64_t>;
13781379

1379-
template llvm::Expected<llvm::ArrayRef<llvm::object::XCOFFRelocation64>>
1380-
llvm::object::XCOFFObjectFile::relocations<llvm::object::XCOFFSectionHeader64,
1381-
llvm::object::XCOFFRelocation64>(
1382-
llvm::object::XCOFFSectionHeader64 const &) const;
1383-
template llvm::Expected<llvm::ArrayRef<llvm::object::XCOFFRelocation32>>
1384-
llvm::object::XCOFFObjectFile::relocations<llvm::object::XCOFFSectionHeader32,
1385-
llvm::object::XCOFFRelocation32>(
1386-
llvm::object::XCOFFSectionHeader32 const &) const;
1380+
template LLVM_EXPORT_TEMPLATE
1381+
llvm::Expected<llvm::ArrayRef<llvm::object::XCOFFRelocation64>>
1382+
llvm::object::XCOFFObjectFile::relocations<
1383+
llvm::object::XCOFFSectionHeader64, llvm::object::XCOFFRelocation64>(
1384+
llvm::object::XCOFFSectionHeader64 const &) const;
1385+
template LLVM_EXPORT_TEMPLATE
1386+
llvm::Expected<llvm::ArrayRef<llvm::object::XCOFFRelocation32>>
1387+
llvm::object::XCOFFObjectFile::relocations<
1388+
llvm::object::XCOFFSectionHeader32, llvm::object::XCOFFRelocation32>(
1389+
llvm::object::XCOFFSectionHeader32 const &) const;
13871390

13881391
bool doesXCOFFTracebackTableBegin(ArrayRef<uint8_t> Bytes) {
13891392
if (Bytes.size() < 4)

0 commit comments

Comments
 (0)