Skip to content

Commit 6bfb189

Browse files
committed
Use session scoped logger instance for unhandled relocation information
Ran into this when running over certain object files on ppc, we can do it for all of them though.
1 parent 9dbc09d commit 6bfb189

File tree

4 files changed

+41
-34
lines changed

4 files changed

+41
-34
lines changed

arch/arm64/arch_arm64.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,9 +2843,8 @@ class Arm64MachoRelocationHandler : public RelocationHandler
28432843
virtual bool GetRelocationInfo(
28442844
Ref<BinaryView> view, Ref<Architecture> arch, vector<BNRelocationInfo>& result) override
28452845
{
2846-
(void)view;
28472846
(void)arch;
2848-
2847+
Ref<Logger> logger = view->CreateLogger("Arm64MachoReloc");
28492848
set<MachoArm64RelocationType> unsupportedRelocations;
28502849
for (size_t i = 0; i < result.size(); i++)
28512850
{
@@ -2897,7 +2896,7 @@ class Arm64MachoRelocationHandler : public RelocationHandler
28972896
}
28982897

28992898
for (auto& relocType : unsupportedRelocations)
2900-
LogWarn("Unsupported relocation: %s (%x)", GetRelocationString(relocType), relocType);
2899+
logger->LogWarn("Unsupported relocation: %s (%x)", GetRelocationString(relocType), relocType);
29012900
return true;
29022901
}
29032902
};
@@ -3159,9 +3158,9 @@ class Arm64ElfRelocationHandler : public RelocationHandler
31593158

31603159
virtual bool GetRelocationInfo(Ref<BinaryView> view, Ref<Architecture> arch, vector<BNRelocationInfo>& result) override
31613160
{
3162-
(void)view;
31633161
(void)arch;
31643162
(void)result;
3163+
Ref<Logger> logger = view->CreateLogger("Arm64ElfReloc");
31653164
set<uint64_t> relocTypes;
31663165
for (auto& reloc : result)
31673166
{
@@ -3253,7 +3252,7 @@ class Arm64ElfRelocationHandler : public RelocationHandler
32533252
}
32543253
}
32553254
for (auto& reloc : relocTypes)
3256-
LogWarn("Unsupported ELF relocation type: %s", GetRelocationString((ElfArm64RelocationType)reloc));
3255+
logger->LogWarn("Unsupported ELF relocation type: %s", GetRelocationString((ElfArm64RelocationType)reloc));
32573256
return true;
32583257
}
32593258

@@ -3282,16 +3281,16 @@ class Arm64PeRelocationHandler : public RelocationHandler
32823281
virtual bool GetRelocationInfo(
32833282
Ref<BinaryView> view, Ref<Architecture> arch, vector<BNRelocationInfo>& result) override
32843283
{
3285-
(void)view;
32863284
(void)arch;
3285+
Ref<Logger> logger = view->CreateLogger("Arm64PeReloc");
32873286
set<uint64_t> relocTypes;
32883287
for (auto& reloc : result)
32893288
{
32903289
reloc.type = UnhandledRelocation;
32913290
relocTypes.insert(reloc.nativeType);
32923291
}
32933292
for (auto& reloc : relocTypes)
3294-
LogWarn(
3293+
logger->LogWarn(
32953294
"Unsupported PE relocation type: %s", GetRelocationString((PeArm64RelocationType)reloc));
32963295
return false;
32973296
}
@@ -3407,8 +3406,8 @@ class Arm64COFFRelocationHandler: public RelocationHandler
34073406

34083407
virtual bool GetRelocationInfo(Ref<BinaryView> view, Ref<Architecture> arch, vector<BNRelocationInfo>& result) override
34093408
{
3410-
(void)view;
34113409
(void)arch;
3410+
Ref<Logger> logger = view->CreateLogger("Arm64CoffReloc");
34123411
set<uint64_t> relocTypes;
34133412
for (auto& reloc : result)
34143413
{
@@ -3477,7 +3476,7 @@ class Arm64COFFRelocationHandler: public RelocationHandler
34773476
}
34783477
}
34793478
for (auto& reloc : relocTypes)
3480-
LogWarn("Unsupported PE relocation type: %s", GetRelocationString((PeArm64RelocationType)reloc));
3479+
logger->LogWarn("Unsupported PE relocation type: %s", GetRelocationString((PeArm64RelocationType)reloc));
34813480
return false;
34823481
}
34833482
};

arch/armv7/arch_armv7.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,8 +2497,8 @@ class ArmElfRelocationHandler: public RelocationHandler
24972497

24982498
virtual bool GetRelocationInfo(Ref<BinaryView> view, Ref<Architecture> arch, vector<BNRelocationInfo>& result) override
24992499
{
2500-
(void)view;
25012500
(void)arch;
2501+
Ref<Logger> logger = view->CreateLogger("ArmElfReloc");
25022502
set<uint64_t> relocTypes;
25032503
for (auto& reloc: result)
25042504
{
@@ -2670,7 +2670,7 @@ class ArmElfRelocationHandler: public RelocationHandler
26702670
}
26712671
}
26722672
for (auto& reloc : relocTypes)
2673-
LogWarn("Unsupported ELF relocation: %s", GetRelocationString((ElfArmRelocationType)reloc));
2673+
logger->LogWarn("Unsupported ELF relocation: %s", GetRelocationString((ElfArmRelocationType)reloc));
26742674
return true;
26752675
}
26762676
};
@@ -2693,16 +2693,16 @@ class ArmMachORelocationHandler: public RelocationHandler
26932693

26942694
virtual bool GetRelocationInfo(Ref<BinaryView> view, Ref<Architecture> arch, vector<BNRelocationInfo>& result) override
26952695
{
2696-
(void)view;
26972696
(void)arch;
2697+
Ref<Logger> logger = view->CreateLogger("ArmMachoReloc");
26982698
set<uint64_t> relocTypes;
26992699
for (auto& reloc: result)
27002700
{
27012701
reloc.type = UnhandledRelocation;
27022702
relocTypes.insert(reloc.nativeType);
27032703
}
27042704
for (auto& reloc : relocTypes)
2705-
LogWarn("Unsupported Mach-O relocation %s", GetRelocationString((MachoArmRelocationType)reloc));
2705+
logger->LogWarn("Unsupported Mach-O relocation %s", GetRelocationString((MachoArmRelocationType)reloc));
27062706
return false;
27072707
};
27082708
};
@@ -2745,8 +2745,8 @@ class ArmPERelocationHandler: public RelocationHandler
27452745

27462746
virtual bool GetRelocationInfo(Ref<BinaryView> view, Ref<Architecture> arch, vector<BNRelocationInfo>& result) override
27472747
{
2748-
(void)view;
27492748
(void)arch;
2749+
Ref<Logger> logger = view->CreateLogger("ArmPeReloc");
27502750
set<uint64_t> relocTypes;
27512751
for (auto& reloc: result)
27522752
{
@@ -2775,7 +2775,7 @@ class ArmPERelocationHandler: public RelocationHandler
27752775
}
27762776
}
27772777
for (auto& reloc : relocTypes)
2778-
LogWarn("Unsupported PE relocation %s", GetRelocationString((PeRelocationType)reloc));
2778+
logger->LogWarn("Unsupported PE relocation %s", GetRelocationString((PeRelocationType)reloc));
27792779
return false;
27802780
}
27812781

@@ -3162,8 +3162,8 @@ class ArmCOFFRelocationHandler: public RelocationHandler
31623162

31633163
virtual bool GetRelocationInfo(Ref<BinaryView> view, Ref<Architecture> arch, vector<BNRelocationInfo>& result) override
31643164
{
3165-
(void)view;
31663165
(void)arch;
3166+
Ref<Logger> logger = view->CreateLogger("ArmCoffReloc");
31673167
set<uint64_t> relocTypes;
31683168
for (auto& reloc: result)
31693169
{
@@ -3236,7 +3236,7 @@ class ArmCOFFRelocationHandler: public RelocationHandler
32363236
}
32373237
}
32383238
for (auto& reloc : relocTypes)
3239-
LogWarn("Unsupported COFF relocation %s", GetRelocationString((PeArmRelocationType)reloc));
3239+
logger->LogWarn("Unsupported COFF relocation %s", GetRelocationString((PeArmRelocationType)reloc));
32403240
return true;
32413241
}
32423242
};

arch/powerpc/arch_ppc.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,7 +2469,8 @@ class PpcElfRelocationHandler: public RelocationHandler
24692469

24702470
virtual bool GetRelocationInfo(Ref<BinaryView> view, Ref<Architecture> arch, vector<BNRelocationInfo>& result) override
24712471
{
2472-
(void)view; (void)arch; (void)result;
2472+
(void)arch; (void)result;
2473+
Ref<Logger> logger = view->CreateLogger("PpcElfReloc");
24732474
set<uint64_t> relocTypes;
24742475
for (auto& reloc : result)
24752476
{
@@ -2526,7 +2527,7 @@ class PpcElfRelocationHandler: public RelocationHandler
25262527
}
25272528
}
25282529
for (auto& reloc : relocTypes)
2529-
LogWarn("Unsupported ELF relocation type: %s", GetRelocationString((ElfPpcRelocationType)reloc));
2530+
logger->LogWarn("Unsupported ELF relocation type: %s", GetRelocationString((ElfPpcRelocationType)reloc));
25302531
return true;
25312532
}
25322533

@@ -2555,15 +2556,16 @@ class PpcMachoRelocationHandler: public RelocationHandler
25552556
public:
25562557
virtual bool GetRelocationInfo(Ref<BinaryView> view, Ref<Architecture> arch, vector<BNRelocationInfo>& result) override
25572558
{
2558-
(void)view; (void)arch;
2559+
(void)arch;
2560+
Ref<Logger> logger = view->CreateLogger("PpcMachoReloc");
25592561
set<uint64_t> relocTypes;
25602562
for (auto& reloc : result)
25612563
{
25622564
reloc.type = UnhandledRelocation;
25632565
relocTypes.insert(reloc.nativeType);
25642566
}
25652567
for (auto& reloc : relocTypes)
2566-
LogWarn("Unsupported Mach-O relocation type: %s", GetRelocationString((MachoPpcRelocationType)reloc));
2568+
logger->LogWarn("Unsupported Mach-O relocation type: %s", GetRelocationString((MachoPpcRelocationType)reloc));
25672569
return false;
25682570
}
25692571
};

arch/x86/arch_x86.cpp

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4058,7 +4058,8 @@ class x86MachoRelocationHandler: public RelocationHandler
40584058

40594059
virtual bool GetRelocationInfo(Ref<BinaryView> view, Ref<Architecture> arch, vector<BNRelocationInfo>& result) override
40604060
{
4061-
(void)view; (void)arch;
4061+
(void)arch;
4062+
Ref<Logger> logger = view->CreateLogger("X86MachoReloc");
40624063
set<uint64_t> relocTypes;
40634064
for (size_t i = 0; i < result.size(); i++)
40644065
{
@@ -4080,7 +4081,7 @@ class x86MachoRelocationHandler: public RelocationHandler
40804081
}
40814082

40824083
for (auto& reloc : relocTypes)
4083-
LogWarn("Unsupported Mach-O relocation type: %s", GetRelocationString((Machox86RelocationType)reloc));
4084+
logger->LogWarn("Unsupported Mach-O relocation type: %s", GetRelocationString((Machox86RelocationType)reloc));
40844085
return true;
40854086
}
40864087
};
@@ -4090,7 +4091,8 @@ class x86ElfRelocationHandler: public RelocationHandler
40904091
public:
40914092
virtual bool GetRelocationInfo(Ref<BinaryView> view, Ref<Architecture> arch, vector<BNRelocationInfo>& result) override
40924093
{
4093-
(void)view; (void)arch;
4094+
(void)arch;
4095+
Ref<Logger> logger = view->CreateLogger("X86ElfReloc");
40944096
set<uint64_t> relocTypes;
40954097
for (auto& reloc : result)
40964098
{
@@ -4154,7 +4156,7 @@ class x86ElfRelocationHandler: public RelocationHandler
41544156
}
41554157
}
41564158
for (auto& reloc : relocTypes)
4157-
LogWarn("Unsupported ELF relocation type: %s", GetRelocationString((Elfx86RelocationType)reloc));
4159+
logger->LogWarn("Unsupported ELF relocation type: %s", GetRelocationString((Elfx86RelocationType)reloc));
41584160
return true;
41594161
}
41604162
};
@@ -4221,7 +4223,8 @@ class x64MachoRelocationHandler: public RelocationHandler
42214223

42224224
virtual bool GetRelocationInfo(Ref<BinaryView> view, Ref<Architecture> arch, vector<BNRelocationInfo>& result) override
42234225
{
4224-
(void)view; (void)arch;
4226+
(void)arch;
4227+
Ref<Logger> logger = view->CreateLogger("X86MachoReloc");
42254228
set<uint64_t> relocTypes;
42264229
for (size_t i = 0; i < result.size(); i++)
42274230
{
@@ -4286,7 +4289,7 @@ class x64MachoRelocationHandler: public RelocationHandler
42864289
}
42874290

42884291
for (auto& reloc : relocTypes)
4289-
LogWarn("Unsupported Mach-O relocation: %s", GetRelocationString((Machox64RelocationType)reloc));
4292+
logger->LogWarn("Unsupported Mach-O relocation: %s", GetRelocationString((Machox64RelocationType)reloc));
42904293
return true;
42914294
}
42924295
};
@@ -4345,7 +4348,8 @@ class x64ElfRelocationHandler: public RelocationHandler
43454348
The AMD64 ILP32 ABI architecture uses only Elf32_Rela relocation entries in relocatable files. Relocations
43464349
contained within executable files or shared objects may use either Elf32_Rela relocation or Elf32_Rel relocation.
43474350
*/
4348-
(void)view; (void)arch;
4351+
(void)arch;
4352+
Ref<Logger> logger = view->CreateLogger("X86ElfReloc");
43494353
set<uint64_t> relocTypes;
43504354
for (auto& reloc : result)
43514355
{
@@ -4477,7 +4481,7 @@ class x64ElfRelocationHandler: public RelocationHandler
44774481
}
44784482
}
44794483
for (auto& reloc : relocTypes)
4480-
LogWarn("Unsupported ELF relocation: %s", GetRelocationString((Elfx64RelocationType)reloc));
4484+
logger->LogWarn("Unsupported ELF relocation: %s", GetRelocationString((Elfx64RelocationType)reloc));
44814485
return true;
44824486
}
44834487
};
@@ -4547,7 +4551,8 @@ class CoffRelocationHandler: public RelocationHandler
45474551

45484552
virtual bool GetRelocationInfo(Ref<BinaryView> view, Ref<Architecture> arch, vector<BNRelocationInfo>& result) override
45494553
{
4550-
(void)view; (void)arch;
4554+
(void)arch;
4555+
Ref<Logger> logger = view->CreateLogger("X86CoffReloc");
45514556
set<uint64_t> relocTypes;
45524557
for (auto& reloc : result)
45534558
{
@@ -4608,7 +4613,7 @@ class CoffRelocationHandler: public RelocationHandler
46084613
relocTypes.insert(reloc.nativeType);
46094614
}
46104615
for (auto& reloc : relocTypes)
4611-
LogWarn("Unsupported COFF relocation: %s", GetRelocationString((COFFx64RelocationType)reloc));
4616+
logger->LogWarn("Unsupported COFF relocation: %s", GetRelocationString((COFFx64RelocationType)reloc));
46124617
}
46134618
else if (arch->GetName() == "x86")
46144619
{
@@ -4652,7 +4657,7 @@ class CoffRelocationHandler: public RelocationHandler
46524657
relocTypes.insert(reloc.nativeType);
46534658
}
46544659
for (auto& reloc : relocTypes)
4655-
LogWarn("Unsupported COFF relocation: %s", GetRelocationString((COFFx86RelocationType)reloc));
4660+
logger->LogWarn("Unsupported COFF relocation: %s", GetRelocationString((COFFx86RelocationType)reloc));
46564661
}
46574662
}
46584663

@@ -4708,7 +4713,8 @@ class PeRelocationHandler: public RelocationHandler
47084713

47094714
virtual bool GetRelocationInfo(Ref<BinaryView> view, Ref<Architecture> arch, vector<BNRelocationInfo>& result) override
47104715
{
4711-
(void)view; (void)arch;
4716+
(void)arch;
4717+
Ref<Logger> logger = view->CreateLogger("X86PeReloc");
47124718
set<uint64_t> relocTypes;
47134719
for (auto& reloc : result)
47144720
{
@@ -4741,7 +4747,7 @@ class PeRelocationHandler: public RelocationHandler
47414747
}
47424748

47434749
for (auto& reloc : relocTypes)
4744-
LogWarn("Unsupported PE relocation: %s", GetRelocationString((PeRelocationType)reloc));
4750+
logger->LogWarn("Unsupported PE relocation: %s", GetRelocationString((PeRelocationType)reloc));
47454751
return false;
47464752
}
47474753

0 commit comments

Comments
 (0)