Skip to content

Commit 346e1c9

Browse files
jgautier-anssifabienfl-orc
authored andcommitted
OrcLib: Enable ARM64 for extension libraries
1 parent c7dcc59 commit 346e1c9

18 files changed

+117
-51
lines changed

src/OrcLib/ApacheOrcOutputWriter.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ApacheOrcOutputWriter : public TableOutputExtension
1919
{
2020
public:
2121
ApacheOrcOutputWriter()
22-
: TableOutputExtension(L"orcapacheorc.dll"s, L"APACHEORC_X86DLL"s, L"APACHEORC_X64DLL"s) {};
22+
: TableOutputExtension(L"orcapacheorc.dll"s, L"APACHEORC_X86DLL"s, L"APACHEORC_X64DLL"s, L"APACHEORC_ARM64DLL"s) {};
2323
~ApacheOrcOutputWriter() {};
2424
};
2525

src/OrcLib/COMExtension.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ namespace Orc {
1818
class COMExtension : public ExtensionLibrary
1919
{
2020
public:
21-
COMExtension(const std::wstring& strKeyword, const std::wstring& strX86LibRef, const std::wstring& strX64LibRef)
22-
: ExtensionLibrary(strKeyword, strX86LibRef, strX64LibRef) {};
21+
COMExtension(const std::wstring& strKeyword, const std::wstring& strLibRef)
22+
: ExtensionLibrary(strKeyword, strLibRef, strLibRef, strLibRef) {};
23+
24+
COMExtension(const std::wstring& strKeyword, const std::wstring& strX86LibRef, const std::wstring& strX64LibRef, const std::wstring& strARM64LibRef)
25+
: ExtensionLibrary(strKeyword, strX86LibRef, strX64LibRef, strARM64LibRef) {};
2326

2427
virtual std::pair<HRESULT, HINSTANCE> LoadThisLibrary(const std::wstring& strLibFile);
2528

src/OrcLib/CompressAPIExtension.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class CompressAPIExtension : public ExtensionLibrary
5151
{
5252
public:
5353
CompressAPIExtension()
54-
: ExtensionLibrary(L"cabinet", L"cabinet.dll", L"cabinet.dll") {};
54+
: ExtensionLibrary(L"cabinet", L"cabinet.dll") {};
5555

5656
STDMETHOD(Initialize)();
5757

src/OrcLib/DbgHelpLibrary.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ using namespace Orc;
1717
using namespace std::string_literals;
1818

1919
DbgHelpLibrary::DbgHelpLibrary()
20-
: ExtensionLibrary(L"DbgHelp.dll"s, L"DBGHELP_X86DLL"s, L"DBGHELP_X64DLL"s)
20+
: ExtensionLibrary(L"DbgHelp.dll"s, L"DBGHELP_X86DLL"s, L"DBGHELP_X64DLL"s, L"DBGHELP_ARM64DLL"s)
2121
{
2222
m_strDesiredName = L"DbgHelp.dll"s;
2323
}

src/OrcLib/EmbeddedResource.h

+49-30
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,27 @@
2323

2424
namespace Orc {
2525

26+
using namespace std::string_view_literals;
27+
2628
class EmbeddedResource
2729
{
2830
public:
31+
static constexpr auto RUN_FMT = L"RUN{}"sv;
32+
static constexpr auto RUN_ARGS_FMT = L"RUN{}_ARGS"sv;
33+
static constexpr auto _32 = L"32"sv;
34+
static constexpr auto _64 = L"64"sv;
35+
static constexpr auto _ARM64 = L"_ARM64"sv;
36+
37+
static auto RUN() { return fmt::format(RUN_FMT, L""sv); }
38+
static auto RUN_32() { return fmt::format(RUN_FMT, _32); }
39+
static auto RUN_64() { return fmt::format(RUN_FMT, _64); }
40+
static auto RUN_ARM64() { return fmt::format(RUN_FMT, _ARM64); }
41+
42+
static auto RUN_ARGS() { return fmt::format(RUN_ARGS_FMT, L""sv); }
43+
static auto RUN_32_ARGS() { return fmt::format(RUN_ARGS_FMT, _32); }
44+
static auto RUN_64_ARGS() { return fmt::format(RUN_ARGS_FMT, _64); }
45+
static auto RUN_ARM64_ARGS() { return fmt::format(RUN_ARGS_FMT, _ARM64); }
46+
2947
class EmbedSpec
3048
{
3149

@@ -158,71 +176,63 @@ class EmbeddedResource
158176
{
159177
EmbedSpec retval;
160178
retval.Type = EmbedType::NameValuePair;
161-
retval.Name = L"RUN";
179+
retval.Name = RUN();
162180
retval.Value = Value;
163181
return retval;
164182
};
165-
static EmbedSpec AddRun(std::wstring&& Value)
166-
{
167-
EmbedSpec retval;
168-
retval.Type = EmbedType::NameValuePair;
169-
retval.Name = L"RUN";
170-
std::swap(retval.Value, Value);
171-
return retval;
172-
};
173183
static EmbedSpec AddRunX86(const std::wstring& Value)
174184
{
175185
EmbedSpec retval;
176186
retval.Type = EmbedType::NameValuePair;
177-
retval.Name = L"RUN32";
187+
retval.Name = RUN_32();
178188
retval.Value = Value;
179189
return retval;
180190
};
181-
static EmbedSpec AddRunX86(std::wstring&& Value)
191+
static EmbedSpec AddRunX64(const std::wstring& Value)
182192
{
183193
EmbedSpec retval;
184194
retval.Type = EmbedType::NameValuePair;
185-
retval.Name = L"RUN32";
186-
std::swap(retval.Value, Value);
195+
retval.Name = RUN_64();
196+
retval.Value = Value;
187197
return retval;
188198
};
189-
static EmbedSpec AddRunX64(std::wstring&& Value)
199+
static EmbedSpec AddRun_ARM64(const std::wstring& Value)
190200
{
191201
EmbedSpec retval;
192202
retval.Type = EmbedType::NameValuePair;
193-
retval.Name = L"RUN64";
194-
std::swap(retval.Value, Value);
203+
retval.Name = RUN_ARM64();
204+
retval.Value = Value;
195205
return retval;
196206
};
197-
static EmbedSpec AddRunX64(const std::wstring& Value)
207+
static EmbedSpec AddRunArgs(const std::wstring& Value)
198208
{
199209
EmbedSpec retval;
200210
retval.Type = EmbedType::NameValuePair;
201-
retval.Name = L"RUN64";
211+
retval.Name = RUN_ARGS();
202212
retval.Value = Value;
203213
return retval;
204214
};
205-
static EmbedSpec AddRunArgs(const std::wstring& Value)
215+
static EmbedSpec AddRun32Args(const std::wstring& Value)
206216
{
207217
EmbedSpec retval;
208218
retval.Type = EmbedType::NameValuePair;
209-
retval.Name = L"RUN_ARGS";
219+
retval.Name = RUN_32_ARGS();
210220
retval.Value = Value;
211221
return retval;
212222
};
213-
static EmbedSpec AddRun32Args(const std::wstring& Value)
223+
static EmbedSpec AddRun64Args(const std::wstring& Value)
214224
{
215225
EmbedSpec retval;
216226
retval.Type = EmbedType::NameValuePair;
217-
retval.Name = L"RUN32_ARGS";
227+
retval.Name = RUN_64_ARGS();
218228
retval.Value = Value;
219229
return retval;
220230
};
221-
static EmbedSpec AddRun64Args(const std::wstring& Value)
231+
static EmbedSpec AddRun_ARM64_Args(const std::wstring& Value)
222232
{
223233
EmbedSpec retval;
224234
retval.Type = EmbedType::NameValuePair;
225-
retval.Name = L"RUN64_ARGS";
235+
retval.Name = RUN_ARM64_ARGS();
226236
retval.Value = Value;
227237
return retval;
228238
};
@@ -389,15 +399,19 @@ class EmbeddedResource
389399

390400
static HRESULT ExtractRun(const std::wstring& Module, std::wstring& Value)
391401
{
392-
return ExtractValue(Module, std::wstring(L"RUN"), Value);
402+
return ExtractValue(Module, fmt::format(RUN_FMT, L""), Value);
393403
}
394404
static HRESULT ExtractRun32(const std::wstring& Module, std::wstring& Value)
395405
{
396-
return ExtractValue(Module, std::wstring(L"RUN32"), Value);
406+
return ExtractValue(Module, fmt::format(RUN_FMT, _32), Value);
397407
}
398408
static HRESULT ExtractRun64(const std::wstring& Module, std::wstring& Value)
399409
{
400-
return ExtractValue(Module, std::wstring(L"RUN64"), Value);
410+
return ExtractValue(Module, fmt::format(RUN_FMT, _64), Value);
411+
}
412+
static HRESULT ExtractRunARM64(const std::wstring& Module, std::wstring& Value)
413+
{
414+
return ExtractValue(Module, fmt::format(RUN_FMT, _ARM64), Value);
401415
}
402416

403417
static HRESULT
@@ -406,17 +420,22 @@ class EmbeddedResource
406420

407421
static HRESULT ExtractRunArgs(const std::wstring& Module, std::wstring& Value)
408422
{
409-
return ExtractValue(Module, std::wstring(L"RUN_ARGS"), Value);
423+
return ExtractValue(Module, RUN_ARGS(), Value);
410424
}
411425

412426
static HRESULT ExtractRun32Args(const std::wstring& Module, std::wstring& Value)
413427
{
414-
return ExtractValue(Module, std::wstring(L"RUN32_ARGS"), Value);
428+
return ExtractValue(Module, RUN_32_ARGS(), Value);
415429
}
416430

417431
static HRESULT ExtractRun64Args(const std::wstring& Module, std::wstring& Value)
418432
{
419-
return ExtractValue(Module, std::wstring(L"RUN64_ARGS"), Value);
433+
return ExtractValue(Module, RUN_64_ARGS(), Value);
434+
}
435+
436+
static HRESULT ExtractRunARM64Args(const std::wstring& Module, std::wstring& Value)
437+
{
438+
return ExtractValue(Module, RUN_ARM64_ARGS(), Value);
420439
}
421440

422441
static HRESULT EnumValues(const std::wstring& Module, std::vector<EmbedSpec>& values);

src/OrcLib/EmbeddedResource_Extract.cpp

+25-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232

3333
#include "Log/Log.h"
3434

35+
#ifndef PROCESSOR_ARCHITECTURE_ARM64
36+
# define PROCESSOR_ARCHITECTURE_ARM64 12
37+
#endif
38+
3539
using namespace std;
3640
namespace fs = std::filesystem;
3741

@@ -328,6 +332,14 @@ bool EmbeddedResource::IsConfiguredToRun()
328332
}
329333
}
330334
break;
335+
case PROCESSOR_ARCHITECTURE_ARM64:
336+
if (FAILED(hr = EmbeddedResource::ExtractRunARM64(L"", strToExecuteRef)))
337+
{
338+
if (FAILED(hr = EmbeddedResource::ExtractRun(L"", strToExecuteRef)))
339+
{
340+
return false;
341+
}
342+
}
331343
default:
332344
return false;
333345
}
@@ -379,8 +391,20 @@ HRESULT EmbeddedResource::ExtractRunWithArgs(
379391
}
380392
else
381393
EmbeddedResource::ExtractRun64Args(L"", strRunArgs);
382-
383394
break;
395+
case PROCESSOR_ARCHITECTURE_ARM64:
396+
if (FAILED(hr = EmbeddedResource::ExtractRunARM64(L"", strToExecuteRef)))
397+
{
398+
if (FAILED(hr = EmbeddedResource::ExtractRun(L"", strToExecuteRef)))
399+
{
400+
Log::Error(L"Not RUN resource found to execute [{}]", SystemError(hr));
401+
return hr;
402+
}
403+
else
404+
EmbeddedResource::ExtractRunArgs(L"", strRunArgs);
405+
}
406+
else
407+
EmbeddedResource::ExtractRunARM64Args(L"", strRunArgs);
384408
default:
385409
Log::Error("Architecture '{}' is not supported", Arch);
386410
return E_FAIL;

src/OrcLib/EvtLibrary.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class EvtLibrary : public ExtensionLibrary
173173

174174
public:
175175
EvtLibrary()
176-
: ExtensionLibrary(L"wevtapi", L"Wevtapi.dll", L"Wevtapi.dll") {};
176+
: ExtensionLibrary(L"wevtapi", L"Wevtapi.dll") {};
177177

178178
STDMETHOD(Initialize)();
179179

src/OrcLib/ExtensionLibrary.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,20 @@
3030
using namespace std;
3131
using namespace Orc;
3232

33-
namespace Orc {
34-
35-
}
33+
#ifndef PROCESSOR_ARCHITECTURE_ARM64
34+
# define PROCESSOR_ARCHITECTURE_ARM64 12
35+
#endif
3636

3737
ExtensionLibrary::ExtensionLibrary(
3838
const std::wstring& strKeyword,
3939
const std::wstring& strX86LibRef,
4040
const std::wstring& strX64LibRef,
41+
const std::wstring& strARM64LibRef,
4142
std::vector<std::shared_ptr<DependencyLibrary>> dependencies)
4243
: m_strKeyword(strKeyword)
4344
, m_strX86LibRef(strX86LibRef)
4445
, m_strX64LibRef(strX64LibRef)
46+
, m_strARM64LibRef(strARM64LibRef)
4547
, m_Dependencies(std::move(dependencies))
4648
{
4749
}
@@ -50,6 +52,11 @@ HRESULT Orc::ExtensionLibrary::LoadDependencies(std::optional<std::filesystem::p
5052
{
5153
for (const auto& dependency : m_Dependencies)
5254
{
55+
if( !dependency)
56+
{
57+
Log::Error(L"Failed to load dependency for library '{}'", m_strKeyword);
58+
continue;
59+
}
5360
if (dependency->IsLoaded())
5461
continue;
5562
if (auto hr = dependency->Load(tempDir); FAILED(hr))
@@ -380,6 +387,9 @@ HRESULT ExtensionLibrary::Load(std::optional<std::filesystem::path> tempDir)
380387
else
381388
m_strLibRef = m_strX64LibRef;
382389
break;
390+
case PROCESSOR_ARCHITECTURE_ARM64:
391+
m_strLibRef = m_strARM64LibRef;
392+
break;
383393
default:
384394
Log::Error(L"Unsupported architecture: {}", wArch);
385395
return HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED);

src/OrcLib/ExtensionLibrary.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,16 @@ class ExtensionLibrary
3939
friend class ExtensionLibraryHandler;
4040

4141
public:
42+
43+
ExtensionLibrary(const std::wstring& strKeyword,
44+
const std::wstring& strLibRef,
45+
std::vector<std::shared_ptr<DependencyLibrary>> dependencies = {}
46+
) : ExtensionLibrary(strKeyword, strLibRef, strLibRef, strLibRef, std::move(dependencies)) {};
47+
4248
ExtensionLibrary(const std::wstring& strKeyword,
4349
const std::wstring& strX86LibRef,
4450
const std::wstring& strX64LibRef,
51+
const std::wstring& strARM64LibRef,
4552
std::vector<std::shared_ptr<DependencyLibrary>> dependencies = {}
4653
);
4754

@@ -207,6 +214,7 @@ class ExtensionLibrary
207214
// There are the default Library refs
208215
std::wstring m_strX86LibRef;
209216
std::wstring m_strX64LibRef;
217+
std::wstring m_strARM64LibRef;
210218

211219
std::wstring m_strLibRef; // Effective, contextual ref used to locate extension lib
212220

@@ -295,7 +303,7 @@ class TemplateExtension : public ExtensionLibrary
295303

296304
public:
297305
TemplateExtension()
298-
: ExtensionLibrary(L"template", L"template.dll", L"template.dll") {};
306+
: ExtensionLibrary(L"template", L"template.dll", L"template.dll", L"template.dll") {};
299307
virtual ~TemplateExtension() {}
300308
STDMETHOD(Initialize)() { return S_OK; }
301309
};

src/OrcLib/Kernel32Extension.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Kernel32Extension : public ExtensionLibrary
2626

2727
public:
2828
Kernel32Extension()
29-
: ExtensionLibrary(L"kernel32"s, L"kernel32.dll"s, L"kernel32.dll"s) {};
29+
: ExtensionLibrary(L"kernel32"s, L"kernel32.dll"s) {};
3030

3131
template <typename... Args>
3232
auto InitializeProcThreadAttributeList(Args&&... args)

src/OrcLib/MSIExtension.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class MSIExtension : public ExtensionLibrary
2525

2626
public:
2727
MSIExtension()
28-
: ExtensionLibrary(L"msi.dll", L"msi.dll", L"msi.dll") {};
28+
: ExtensionLibrary(L"msi", L"msi.dll") {};
2929

3030
STDMETHOD(Initialize)();
3131

src/OrcLib/NtDllExtension.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class NtDllExtension : public ExtensionLibrary
4747

4848
public:
4949
NtDllExtension()
50-
: ExtensionLibrary(L"ntdll", L"ntdll.dll", L"ntdll.dll") {};
50+
: ExtensionLibrary(L"ntdll", L"ntdll.dll") {};
5151
virtual ~NtDllExtension() {}
5252
STDMETHOD(Initialize)();
5353

src/OrcLib/PSAPIExtension.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class PSAPIExtension : public ExtensionLibrary
2525

2626
public:
2727
PSAPIExtension()
28-
: ExtensionLibrary(L"psapi", L"psapi.dll", L"psapi.dll") {};
28+
: ExtensionLibrary(L"psapi", L"psapi.dll") {};
2929

3030
STDMETHOD(Initialize)();
3131

src/OrcLib/ParquetOutputWriter.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ParquetOutputWriter : public TableOutputExtension
1919
{
2020
public:
2121
ParquetOutputWriter()
22-
: TableOutputExtension(L"orcparquet.dll"s, L"ORCPARQUET_X86DLL"s, L"ORCPARQUET_X64DLL"s) {};
22+
: TableOutputExtension(L"orcparquet.dll"s, L"ORCPARQUET_X86DLL"s, L"ORCPARQUET_X64DLL"s, L"ORCPARQUET_ARM64DLL"s) {};
2323
~ParquetOutputWriter() {};
2424
};
2525

0 commit comments

Comments
 (0)