-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmacho_relocatable_file.cpp
9430 lines (8705 loc) · 356 KB
/
macho_relocatable_file.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
*
* Copyright (c) 2009-2010 Apple Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
#include <stdint.h>
#include <stdlib.h>
#include <math.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include "MachOFileAbstraction.hpp"
#include "libunwind/DwarfInstructions.hpp"
#include "libunwind/AddressSpace.hpp"
#include "libunwind/Registers.hpp"
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <type_traits>
#include "dwarf2.h"
#include "debugline.h"
#include "Architectures.hpp"
#include "Bitcode.hpp"
#include "ld.hpp"
#include "macho_relocatable_file.h"
extern void throwf(const char* format, ...) __attribute__ ((noreturn,format(printf, 1, 2)));
extern void warning(const char* format, ...) __attribute__((format(printf, 1, 2)));
namespace mach_o {
namespace relocatable {
// forward reference
template <typename A> class Parser;
template <typename A> class Atom;
template <typename A> class Section;
template <typename A> class CFISection;
template <typename A> class CUSection;
template <typename A>
class File : public ld::relocatable::File
{
public:
File(const char* p, time_t mTime, const uint8_t* content, ld::File::Ordinal ord) :
ld::relocatable::File(p,mTime,ord), _fileContent(content),
_sectionsArray(NULL), _atomsArray(NULL),
_sectionsArrayCount(0), _atomsArrayCount(0), _aliasAtomsArrayCount(0),
_debugInfoKind(ld::relocatable::File::kDebugInfoNone),
_dwarfTranslationUnitPath(NULL),
_dwarfDebugInfoSect(NULL), _dwarfDebugAbbrevSect(NULL),
_dwarfDebugLineSect(NULL), _dwarfDebugStringSect(NULL),
_hasObjC(false),
_swiftVersion(0),
_swiftLanguageVersion(0),
_cpuSubType(0),
_minOSVersion(0),
_canScatterAtoms(false),
_hasllvmProfiling(false),
_objcHasSignedClassROs(false),
_objcHasCategoryClassPropertiesField(false),
_srcKind(kSourceUnknown) { }
virtual ~File();
// overrides of ld::File
virtual bool forEachAtom(ld::File::AtomHandler&) const;
virtual bool justInTimeforEachAtom(const char* name, ld::File::AtomHandler&) const
{ return false; }
virtual const ld::VersionSet& platforms() const { return _platforms; }
// overrides of ld::relocatable::File
virtual bool hasObjC() const { return _hasObjC; }
virtual bool objcHasSignedClassROs() const { return _objcHasSignedClassROs; }
virtual bool objcHasCategoryClassPropertiesField() const
{ return _objcHasCategoryClassPropertiesField; }
virtual uint32_t cpuSubType() const { return _cpuSubType; }
virtual uint8_t cpuSubTypeFlags() const { return _cpuSubTypeFlags; }
virtual DebugInfoKind debugInfo() const { return _debugInfoKind; }
virtual const std::vector<ld::relocatable::File::Stab>* stabs() const { return &_stabs; }
virtual bool canScatterAtoms() const { return _canScatterAtoms; }
virtual bool hasllvmProfiling() const { return _hasllvmProfiling; }
virtual const char* translationUnitSource() const;
virtual LinkerOptionsList* linkerOptions() const { return &_linkerOptions; }
virtual const ToolVersionList& toolVersions() const { return _toolVersions; }
virtual uint8_t swiftVersion() const { return _swiftVersion; }
virtual uint16_t swiftLanguageVersion() const { return _swiftLanguageVersion; }
virtual ld::Bitcode* getBitcode() const { return _bitcode.get(); }
virtual SourceKind sourceKind() const { return _srcKind; }
virtual const uint8_t* fileContent() const { return _fileContent; }
virtual const std::vector<AstTimeAndPath>* astFiles() const { return &_astFiles; }
void setHasllvmProfiling() { _hasllvmProfiling = true; }
private:
friend class Atom<A>;
friend class Section<A>;
friend class Parser<A>;
friend class CFISection<A>::OAS;
typedef typename A::P P;
const uint8_t* _fileContent;
Section<A>** _sectionsArray;
uint8_t* _atomsArray;
uint8_t* _aliasAtomsArray;
uint32_t _sectionsArrayCount;
uint32_t _atomsArrayCount;
uint32_t _aliasAtomsArrayCount;
std::vector<ld::Fixup> _fixups;
std::vector<ld::Atom::UnwindInfo> _unwindInfos;
std::vector<ld::Atom::LineInfo> _lineInfos;
std::vector<ld::relocatable::File::Stab>_stabs;
std::vector<AstTimeAndPath> _astFiles;
ld::relocatable::File::DebugInfoKind _debugInfoKind;
const char* _dwarfTranslationUnitPath;
const macho_section<P>* _dwarfDebugInfoSect;
const macho_section<P>* _dwarfDebugAbbrevSect;
const macho_section<P>* _dwarfDebugLineSect;
const macho_section<P>* _dwarfDebugStringSect;
const macho_section<P>* _dwarfDebugStringOffsSect;
bool _hasObjC;
uint8_t _swiftVersion;
uint16_t _swiftLanguageVersion;
uint32_t _cpuSubType;
uint8_t _cpuSubTypeFlags;
uint32_t _minOSVersion;
ld::VersionSet _platforms;
bool _canScatterAtoms;
bool _hasllvmProfiling;
bool _objcHasSignedClassROs;
bool _objcHasCategoryClassPropertiesField;
std::vector<std::vector<const char*> > _linkerOptions;
std::unique_ptr<ld::Bitcode> _bitcode;
SourceKind _srcKind;
ToolVersionList _toolVersions;
};
template <typename A>
class Section : public ld::Section
{
public:
typedef typename A::P::uint_t pint_t;
typedef typename A::P P;
typedef typename A::P::E E;
virtual ~Section() { }
class File<A>& file() const { return _file; }
const macho_section<P>* machoSection() const { return _machOSection; }
uint32_t sectionNum(class Parser<A>&) const;
virtual ld::Atom::Alignment alignmentForAddress(pint_t addr);
virtual ld::Atom::ContentType contentType() { return ld::Atom::typeUnclassified; }
virtual bool dontDeadStrip() { return (this->_machOSection->flags() & S_ATTR_NO_DEAD_STRIP); }
virtual bool dontDeadStripIfReferencesLive() { return ( (this->_machOSection != NULL) && (this->_machOSection->flags() & S_ATTR_LIVE_SUPPORT) ); }
virtual Atom<A>* findAtomByAddress(pint_t addr) { return this->findContentAtomByAddress(addr, this->_beginAtoms, this->_endAtoms); }
virtual bool addFollowOnFixups() const { return ! _file.canScatterAtoms(); }
virtual uint32_t appendAtoms(class Parser<A>& parser, uint8_t* buffer,
struct Parser<A>::LabelAndCFIBreakIterator& it,
const struct Parser<A>::CFI_CU_InfoArrays&) = 0;
virtual uint32_t computeAtomCount(class Parser<A>& parser,
struct Parser<A>::LabelAndCFIBreakIterator& it,
const struct Parser<A>::CFI_CU_InfoArrays&) = 0;
virtual void makeFixups(class Parser<A>& parser, const struct Parser<A>::CFI_CU_InfoArrays&);
virtual bool addRelocFixup(class Parser<A>& parser, const macho_relocation_info<P>*);
virtual unsigned long contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const { return 0; }
virtual bool canCoalesceWith(const class Atom<A>* atom, const ld::Atom& rhs,
const ld::IndirectBindingTable& ind) const { return false; }
virtual bool ignoreLabel(const char* label) const { return false; }
void targetFromExternReloc(class Parser<A>& parser, typename Parser<A>::SourceLocation& src,
const macho_relocation_info<P>* reloc, typename Parser<A>::TargetDesc& target);
static const char* makeSectionName(const macho_section<typename A::P>* s);
protected:
Section(File<A>& f, const macho_section<typename A::P>* s)
: ld::Section(makeSegmentName(s), makeSectionName(s), sectionType(s)),
_file(f), _machOSection(s), _beginAtoms(NULL), _endAtoms(NULL), _hasAliases(false) { }
Section(File<A>& f, const char* segName, const char* sectName, ld::Section::Type t, bool hidden=false)
: ld::Section(segName, sectName, t, hidden), _file(f), _machOSection(NULL),
_beginAtoms(NULL), _endAtoms(NULL), _hasAliases(false) { }
Atom<A>* findContentAtomByAddress(pint_t addr, class Atom<A>* start, class Atom<A>* end);
uint32_t x86_64PcRelOffset(uint8_t r_type);
void addLOH(class Parser<A>& parser, int kind, int count, const uint64_t addrs[]);
static const char* makeSegmentName(const macho_section<typename A::P>* s);
static bool readable(const macho_section<typename A::P>* s);
static bool writable(const macho_section<typename A::P>* s);
static bool exectuable(const macho_section<typename A::P>* s);
static ld::Section::Type sectionType(const macho_section<typename A::P>* s);
File<A>& _file;
const macho_section<P>* _machOSection;
class Atom<A>* _beginAtoms;
class Atom<A>* _endAtoms;
bool _hasAliases;
ld::Set<const class Atom<A>*> _altEntries;
};
template <typename A>
class CFISection : public Section<A>
{
public:
CFISection(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s)
: Section<A>(f, s) { }
uint32_t cfiCount(Parser<A>& parser);
virtual ld::Atom::ContentType contentType() { return ld::Atom::typeCFI; }
virtual uint32_t computeAtomCount(class Parser<A>& parser, struct Parser<A>::LabelAndCFIBreakIterator& it, const struct Parser<A>::CFI_CU_InfoArrays&);
virtual uint32_t appendAtoms(class Parser<A>& parser, uint8_t* buffer, struct Parser<A>::LabelAndCFIBreakIterator& it, const struct Parser<A>::CFI_CU_InfoArrays&);
virtual void makeFixups(class Parser<A>& parser, const struct Parser<A>::CFI_CU_InfoArrays&);
virtual bool addFollowOnFixups() const { return false; }
///
/// ObjectFileAddressSpace is used as a template parameter to UnwindCursor for parsing
/// dwarf CFI information in an object file.
///
class OAS
{
public:
typedef typename A::P::uint_t pint_t;
typedef typename A::P P;
typedef typename A::P::E E;
typedef typename A::P::uint_t sint_t;
OAS(CFISection<A>& ehFrameSection, const uint8_t* ehFrameBuffer) :
_ehFrameSection(ehFrameSection),
_ehFrameContent(ehFrameBuffer),
_ehFrameStartAddr(ehFrameSection.machoSection()->addr()),
_ehFrameEndAddr(ehFrameSection.machoSection()->addr()+ehFrameSection.machoSection()->size()) {}
uint8_t get8(pint_t addr) { return *((uint8_t*)mappedAddress(addr)); }
uint16_t get16(pint_t addr) { return E::get16(*((uint16_t*)mappedAddress(addr))); }
uint32_t get32(pint_t addr) { return E::get32(*((uint32_t*)mappedAddress(addr))); }
uint64_t get64(pint_t addr) { return E::get64(*((uint64_t*)mappedAddress(addr))); }
pint_t getP(pint_t addr) { return P::getP(*((pint_t*)mappedAddress(addr))); }
uint64_t getULEB128(pint_t& addr, pint_t end);
int64_t getSLEB128(pint_t& addr, pint_t end);
pint_t getEncodedP(pint_t& addr, pint_t end, uint8_t encoding);
private:
const void* mappedAddress(pint_t addr);
CFISection<A>& _ehFrameSection;
const uint8_t* _ehFrameContent;
pint_t _ehFrameStartAddr;
pint_t _ehFrameEndAddr;
};
typedef typename A::P::uint_t pint_t;
typedef libunwind::CFI_Atom_Info<OAS> CFI_Atom_Info;
void cfiParse(class Parser<A>& parser, uint8_t* buffer, CFI_Atom_Info cfiArray[], uint32_t& cfiCount, const ld::Set<pint_t>& cuStarts, bool canEncodeToDwarf);
bool needsRelocating();
static bool bigEndian();
private:
void addCiePersonalityFixups(class Parser<A>& parser, const CFI_Atom_Info* cieInfo);
static void warnFunc(void* ref, uint64_t funcAddr, const char* msg);
};
template <typename A>
class CUSection : public Section<A>
{
public:
CUSection(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s)
: Section<A>(f, s) { }
typedef typename A::P::uint_t pint_t;
typedef typename A::P P;
typedef typename A::P::E E;
virtual uint32_t computeAtomCount(class Parser<A>& parser, struct Parser<A>::LabelAndCFIBreakIterator& it, const struct Parser<A>::CFI_CU_InfoArrays&) { return 0; }
virtual uint32_t appendAtoms(class Parser<A>& parser, uint8_t* buffer, struct Parser<A>::LabelAndCFIBreakIterator& it, const struct Parser<A>::CFI_CU_InfoArrays&) { return 0; }
virtual void makeFixups(class Parser<A>& parser, const struct Parser<A>::CFI_CU_InfoArrays&);
virtual bool addFollowOnFixups() const { return false; }
struct Info {
pint_t functionStartAddress;
uint32_t functionSymbolIndex;
uint32_t rangeLength;
uint32_t compactUnwindInfo;
const char* personality;
pint_t lsdaAddress;
Atom<A>* function;
Atom<A>* lsda;
};
uint32_t count();
void parse(class Parser<A>& parser, uint32_t cnt, Info array[]);
static bool encodingMeansUseDwarf(compact_unwind_encoding_t enc);
private:
const char* personalityName(class Parser<A>& parser, const macho_relocation_info<P>* reloc);
static int infoSorter(const void* l, const void* r);
};
template <typename A>
class TentativeDefinitionSection : public Section<A>
{
public:
TentativeDefinitionSection(Parser<A>& parser, File<A>& f)
: Section<A>(f, "__DATA", "__comm/tent", ld::Section::typeTentativeDefs) {}
virtual ld::Atom::ContentType contentType() { return ld::Atom::typeZeroFill; }
virtual bool addFollowOnFixups() const { return false; }
virtual Atom<A>* findAtomByAddress(typename A::P::uint_t addr) { throw "TentativeDefinitionSection::findAtomByAddress() should never be called"; }
virtual uint32_t computeAtomCount(class Parser<A>& parser, struct Parser<A>::LabelAndCFIBreakIterator& it,
const struct Parser<A>::CFI_CU_InfoArrays&);
virtual uint32_t appendAtoms(class Parser<A>& parser, uint8_t* buffer,
struct Parser<A>::LabelAndCFIBreakIterator& it,
const struct Parser<A>::CFI_CU_InfoArrays&);
virtual void makeFixups(class Parser<A>& parser, const struct Parser<A>::CFI_CU_InfoArrays&) {}
private:
typedef typename A::P::uint_t pint_t;
typedef typename A::P P;
};
template <typename A>
class AbsoluteSymbolSection : public Section<A>
{
public:
AbsoluteSymbolSection(Parser<A>& parser, File<A>& f)
: Section<A>(f, "__DATA", "__abs", ld::Section::typeAbsoluteSymbols, true) {}
virtual ld::Atom::ContentType contentType() { return ld::Atom::typeUnclassified; }
virtual bool dontDeadStrip() { return false; }
virtual ld::Atom::Alignment alignmentForAddress(typename A::P::uint_t addr) { return ld::Atom::Alignment(0); }
virtual bool addFollowOnFixups() const { return false; }
virtual Atom<A>* findAtomByAddress(typename A::P::uint_t addr) { throw "AbsoluteSymbolSection::findAtomByAddress() should never be called"; }
virtual uint32_t computeAtomCount(class Parser<A>& parser, struct Parser<A>::LabelAndCFIBreakIterator& it,
const struct Parser<A>::CFI_CU_InfoArrays&);
virtual uint32_t appendAtoms(class Parser<A>& parser, uint8_t* buffer,
struct Parser<A>::LabelAndCFIBreakIterator& it,
const struct Parser<A>::CFI_CU_InfoArrays&);
virtual void makeFixups(class Parser<A>& parser, const struct Parser<A>::CFI_CU_InfoArrays&) {}
virtual Atom<A>* findAbsAtomForValue(typename A::P::uint_t);
private:
typedef typename A::P::uint_t pint_t;
typedef typename A::P P;
};
template <typename A>
class SymboledSection : public Section<A>
{
public:
SymboledSection(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s);
virtual ld::Atom::ContentType contentType() { return _type; }
virtual bool dontDeadStrip();
virtual uint32_t computeAtomCount(class Parser<A>& parser, struct Parser<A>::LabelAndCFIBreakIterator& it,
const struct Parser<A>::CFI_CU_InfoArrays&);
virtual uint32_t appendAtoms(class Parser<A>& parser, uint8_t* buffer,
struct Parser<A>::LabelAndCFIBreakIterator& it,
const struct Parser<A>::CFI_CU_InfoArrays&);
protected:
typedef typename A::P::uint_t pint_t;
typedef typename A::P P;
ld::Atom::ContentType _type;
};
template <typename A>
class TLVDefsSection : public SymboledSection<A>
{
public:
TLVDefsSection(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s) :
SymboledSection<A>(parser, f, s) { }
typedef typename A::P::uint_t pint_t;
virtual ld::Atom::Alignment alignmentForAddress(pint_t addr) { return ld::Atom::Alignment(log2(sizeof(pint_t))); }
private:
};
template <typename A>
class ImplicitSizeSection : public Section<A>
{
public:
ImplicitSizeSection(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s)
: Section<A>(f, s) { }
virtual uint32_t computeAtomCount(class Parser<A>& parser, struct Parser<A>::LabelAndCFIBreakIterator& it, const struct Parser<A>::CFI_CU_InfoArrays&);
virtual uint32_t appendAtoms(class Parser<A>& parser, uint8_t* buffer, struct Parser<A>::LabelAndCFIBreakIterator& it, const struct Parser<A>::CFI_CU_InfoArrays&);
protected:
typedef typename A::P::uint_t pint_t;
typedef typename A::P P;
virtual bool addFollowOnFixups() const { return false; }
virtual const char* unlabeledAtomName(Parser<A>& parser, pint_t addr) = 0;
virtual ld::Atom::SymbolTableInclusion symbolTableInclusion();
virtual pint_t elementSizeAtAddress(pint_t addr) = 0;
virtual ld::Atom::Scope scopeAtAddress(Parser<A>& parser, pint_t addr) { return ld::Atom::scopeLinkageUnit; }
virtual bool useElementAt(Parser<A>& parser,
struct Parser<A>::LabelAndCFIBreakIterator& it, pint_t addr) = 0;
virtual ld::Atom::Definition definition() { return ld::Atom::definitionRegular; }
virtual ld::Atom::Combine combine(Parser<A>& parser, pint_t addr) = 0;
virtual bool ignoreLabel(const char* label) const { return (label[0] == 'L'); }
};
template <typename A>
class FixedSizeSection : public ImplicitSizeSection<A>
{
public:
FixedSizeSection(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s)
: ImplicitSizeSection<A>(parser, f, s) { }
protected:
typedef typename A::P::uint_t pint_t;
typedef typename A::P P;
typedef typename A::P::E E;
virtual bool useElementAt(Parser<A>& parser,
struct Parser<A>::LabelAndCFIBreakIterator& it, pint_t addr)
{ return true; }
};
template <typename A>
class Literal4Section : public FixedSizeSection<A>
{
public:
Literal4Section(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s)
: FixedSizeSection<A>(parser, f, s) {}
protected:
typedef typename A::P::uint_t pint_t;
typedef typename A::P P;
virtual ld::Atom::Alignment alignmentForAddress(pint_t addr) { return ld::Atom::Alignment(2); }
virtual const char* unlabeledAtomName(Parser<A>&, pint_t) { return "4-byte-literal"; }
virtual pint_t elementSizeAtAddress(pint_t addr) { return 4; }
virtual ld::Atom::Combine combine(Parser<A>&, pint_t) { return ld::Atom::combineByNameAndContent; }
virtual unsigned long contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const;
virtual bool canCoalesceWith(const class Atom<A>* atom, const ld::Atom& rhs,
const ld::IndirectBindingTable& ind) const;
virtual bool ignoreLabel(const char* label) const;
};
template <typename A>
class Literal8Section : public FixedSizeSection<A>
{
public:
Literal8Section(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s)
: FixedSizeSection<A>(parser, f, s) {}
protected:
typedef typename A::P::uint_t pint_t;
typedef typename A::P P;
virtual ld::Atom::Alignment alignmentForAddress(pint_t addr) { return ld::Atom::Alignment(3); }
virtual const char* unlabeledAtomName(Parser<A>&, pint_t) { return "8-byte-literal"; }
virtual pint_t elementSizeAtAddress(pint_t addr) { return 8; }
virtual ld::Atom::Combine combine(Parser<A>&, pint_t) { return ld::Atom::combineByNameAndContent; }
virtual unsigned long contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const;
virtual bool canCoalesceWith(const class Atom<A>* atom, const ld::Atom& rhs,
const ld::IndirectBindingTable& ind) const;
virtual bool ignoreLabel(const char* label) const;
};
template <typename A>
class Literal16Section : public FixedSizeSection<A>
{
public:
Literal16Section(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s)
: FixedSizeSection<A>(parser, f, s) {}
protected:
typedef typename A::P::uint_t pint_t;
typedef typename A::P P;
virtual ld::Atom::Alignment alignmentForAddress(pint_t addr) { return ld::Atom::Alignment(4); }
virtual const char* unlabeledAtomName(Parser<A>&, pint_t) { return "16-byte-literal"; }
virtual pint_t elementSizeAtAddress(pint_t addr) { return 16; }
virtual ld::Atom::Combine combine(Parser<A>&, pint_t) { return ld::Atom::combineByNameAndContent; }
virtual unsigned long contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const;
virtual bool canCoalesceWith(const class Atom<A>* atom, const ld::Atom& rhs,
const ld::IndirectBindingTable& ind) const;
virtual bool ignoreLabel(const char* label) const;
};
template <typename A>
class NonLazyPointerSection : public FixedSizeSection<A>
{
public:
NonLazyPointerSection(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s)
: FixedSizeSection<A>(parser, f, s) {}
protected:
typedef typename A::P::uint_t pint_t;
typedef typename A::P P;
virtual void makeFixups(class Parser<A>& parser, const struct Parser<A>::CFI_CU_InfoArrays&);
virtual ld::Atom::ContentType contentType() { return ld::Atom::typeNonLazyPointer; }
virtual ld::Atom::Alignment alignmentForAddress(pint_t addr) { return ld::Atom::Alignment(log2(sizeof(pint_t))); }
virtual const char* unlabeledAtomName(Parser<A>&, pint_t) { return "non_lazy_ptr"; }
virtual pint_t elementSizeAtAddress(pint_t addr) { return sizeof(pint_t); }
virtual ld::Atom::Scope scopeAtAddress(Parser<A>& parser, pint_t addr);
virtual ld::Atom::Combine combine(Parser<A>&, pint_t);
virtual bool ignoreLabel(const char* label) const { return true; }
virtual unsigned long contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const;
virtual bool canCoalesceWith(const class Atom<A>* atom, const ld::Atom& rhs,
const ld::IndirectBindingTable& ind) const;
private:
static const char* targetName(const class Atom<A>* atom, const ld::IndirectBindingTable& ind);
static ld::Fixup::Kind fixupKind();
};
template <typename A>
class TLVPointerSection : public FixedSizeSection<A>
{
public:
TLVPointerSection(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s)
: FixedSizeSection<A>(parser, f, s) {}
protected:
typedef typename A::P::uint_t pint_t;
typedef typename A::P P;
virtual void makeFixups(class Parser<A>& parser, const struct Parser<A>::CFI_CU_InfoArrays&);
virtual ld::Atom::ContentType contentType() { return ld::Atom::typeTLVPointer; }
virtual ld::Atom::Alignment alignmentForAddress(pint_t addr) { return ld::Atom::Alignment(log2(sizeof(pint_t))); }
virtual const char* unlabeledAtomName(Parser<A>&, pint_t) { return "tlv_lazy_ptr"; }
virtual pint_t elementSizeAtAddress(pint_t addr) { return sizeof(pint_t); }
virtual ld::Atom::Combine combine(Parser<A>&, pint_t);
virtual bool ignoreLabel(const char* label) const { return true; }
virtual unsigned long contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const;
virtual bool canCoalesceWith(const class Atom<A>* atom, const ld::Atom& rhs,
const ld::IndirectBindingTable& ind) const;
private:
static const char* targetName(const class Atom<A>* atom, const ld::IndirectBindingTable& ind, bool* isStatic);
};
template <typename A>
class CFStringSection : public FixedSizeSection<A>
{
public:
CFStringSection(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s)
: FixedSizeSection<A>(parser, f, s) {}
protected:
typedef typename A::P::uint_t pint_t;
virtual ld::Atom::Alignment alignmentForAddress(pint_t addr) { return ld::Atom::Alignment(log2(sizeof(pint_t))); }
virtual const char* unlabeledAtomName(Parser<A>&, pint_t) { return "CFString"; }
virtual pint_t elementSizeAtAddress(pint_t addr) { return 4*sizeof(pint_t); }
virtual ld::Atom::Combine combine(Parser<A>&, pint_t) { return ld::Atom::combineByNameAndReferences; }
virtual bool ignoreLabel(const char* label) const { return true; }
virtual unsigned long contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const;
virtual bool canCoalesceWith(const class Atom<A>* atom, const ld::Atom& rhs,
const ld::IndirectBindingTable& ind) const;
private:
enum ContentType { contentUTF8, contentUTF16, contentUnknown };
static const uint8_t* targetContent(const class Atom<A>* atom, const ld::IndirectBindingTable& ind,
ContentType* ct, unsigned int* count);
};
template <typename A>
class ObjC1ClassSection : public FixedSizeSection<A>
{
public:
ObjC1ClassSection(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s)
: FixedSizeSection<A>(parser, f, s) {}
protected:
typedef typename A::P::uint_t pint_t;
typedef typename A::P P;
typedef typename A::P::E E;
virtual ld::Atom::Scope scopeAtAddress(Parser<A>& , pint_t ) { return ld::Atom::scopeGlobal; }
virtual ld::Atom::Alignment alignmentForAddress(pint_t addr) { return ld::Atom::Alignment(2); }
virtual const char* unlabeledAtomName(Parser<A>&, pint_t);
virtual ld::Atom::SymbolTableInclusion symbolTableInclusion() { return ld::Atom::symbolTableIn; }
virtual pint_t elementSizeAtAddress(pint_t addr);
virtual ld::Atom::Combine combine(Parser<A>&, pint_t) { return ld::Atom::combineNever; }
virtual bool ignoreLabel(const char* label) const { return true; }
virtual unsigned long contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const
{ return 0; }
virtual bool canCoalesceWith(const class Atom<A>* atom, const ld::Atom& rhs,
const ld::IndirectBindingTable& ind) const { return false; }
virtual bool addRelocFixup(class Parser<A>& parser, const macho_relocation_info<P>*);
};
template <typename A>
class ObjC2ClassRefsSection : public FixedSizeSection<A>
{
public:
ObjC2ClassRefsSection(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s)
: FixedSizeSection<A>(parser, f, s) {}
protected:
typedef typename A::P::uint_t pint_t;
virtual ld::Atom::Alignment alignmentForAddress(pint_t addr) { return ld::Atom::Alignment(log2(sizeof(pint_t))); }
virtual const char* unlabeledAtomName(Parser<A>&, pint_t) { return "objc-class-ref"; }
virtual pint_t elementSizeAtAddress(pint_t addr) { return sizeof(pint_t); }
virtual ld::Atom::Combine combine(Parser<A>&, pint_t) { return ld::Atom::combineByNameAndReferences; }
virtual bool ignoreLabel(const char* label) const { return true; }
virtual unsigned long contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const;
virtual bool canCoalesceWith(const class Atom<A>* atom, const ld::Atom& rhs,
const ld::IndirectBindingTable& ind) const;
private:
const char* targetClassName(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const;
};
template <typename A>
class ObjC2ClassOrCategoryListSection : public FixedSizeSection<A>
{
public:
ObjC2ClassOrCategoryListSection(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s)
: FixedSizeSection<A>(parser, f, s) {}
protected:
typedef typename A::P::uint_t pint_t;
virtual ld::Atom::Alignment alignmentForAddress(pint_t addr) { return ld::Atom::Alignment(log2(sizeof(pint_t))); }
virtual ld::Atom::Scope scopeAtAddress(Parser<A>& parser, pint_t addr) { return ld::Atom::scopeTranslationUnit; }
virtual const char* unlabeledAtomName(Parser<A>&, pint_t) { return "objc-cat-list"; }
virtual pint_t elementSizeAtAddress(pint_t addr) { return sizeof(pint_t); }
virtual ld::Atom::Combine combine(Parser<A>&, pint_t) { return ld::Atom::combineNever; }
virtual bool ignoreLabel(const char* label) const { return true; }
private:
const char* targetClassName(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const;
};
template <typename A>
class PointerToCStringSection : public FixedSizeSection<A>
{
public:
PointerToCStringSection(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s)
: FixedSizeSection<A>(parser, f, s) {}
protected:
typedef typename A::P::uint_t pint_t;
virtual ld::Atom::Alignment alignmentForAddress(pint_t addr) { return ld::Atom::Alignment(log2(sizeof(pint_t))); }
virtual const char* unlabeledAtomName(Parser<A>&, pint_t) { return "pointer-to-literal-cstring"; }
virtual pint_t elementSizeAtAddress(pint_t addr) { return sizeof(pint_t); }
virtual ld::Atom::Combine combine(Parser<A>&, pint_t) { return ld::Atom::combineByNameAndReferences; }
virtual bool ignoreLabel(const char* label) const { return true; }
virtual unsigned long contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const;
virtual bool canCoalesceWith(const class Atom<A>* atom, const ld::Atom& rhs,
const ld::IndirectBindingTable& ind) const;
virtual const char* targetCString(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const;
};
template <typename A>
class Objc1ClassReferences : public PointerToCStringSection<A>
{
public:
Objc1ClassReferences(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s)
: PointerToCStringSection<A>(parser, f, s) {}
typedef typename A::P::uint_t pint_t;
typedef typename A::P P;
virtual const char* unlabeledAtomName(Parser<A>&, pint_t) { return "pointer-to-literal-objc-class-name"; }
virtual bool addRelocFixup(class Parser<A>& parser, const macho_relocation_info<P>*);
virtual const char* targetCString(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const;
};
template <typename A>
class CStringSection : public ImplicitSizeSection<A>
{
public:
CStringSection(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s)
: ImplicitSizeSection<A>(parser, f, s) {}
protected:
typedef typename A::P::uint_t pint_t;
typedef typename A::P P;
virtual ld::Atom::ContentType contentType() { return ld::Atom::typeCString; }
virtual Atom<A>* findAtomByAddress(pint_t addr);
virtual const char* unlabeledAtomName(Parser<A>&, pint_t) { return "cstring"; }
virtual pint_t elementSizeAtAddress(pint_t addr);
virtual bool ignoreLabel(const char* label) const;
virtual bool useElementAt(Parser<A>& parser,
struct Parser<A>::LabelAndCFIBreakIterator& it, pint_t addr);
virtual ld::Atom::Combine combine(Parser<A>&, pint_t) { return ld::Atom::combineByNameAndContent; }
virtual unsigned long contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const;
virtual bool canCoalesceWith(const class Atom<A>* atom, const ld::Atom& rhs,
const ld::IndirectBindingTable& ind) const;
};
template <typename A>
class UTF16StringSection : public SymboledSection<A>
{
public:
UTF16StringSection(Parser<A>& parser, File<A>& f, const macho_section<typename A::P>* s)
: SymboledSection<A>(parser, f, s) {}
protected:
typedef typename A::P::uint_t pint_t;
typedef typename A::P P;
virtual ld::Atom::Combine combine(Parser<A>&, pint_t) { return ld::Atom::combineByNameAndContent; }
virtual unsigned long contentHash(const class Atom<A>* atom, const ld::IndirectBindingTable& ind) const;
virtual bool canCoalesceWith(const class Atom<A>* atom, const ld::Atom& rhs,
const ld::IndirectBindingTable& ind) const;
};
//
// Atoms in mach-o files
//
template <typename A>
class Atom : public ld::Atom
{
public:
// overrides of ld::Atom
virtual const ld::File* file() const;
virtual const char* translationUnitSource() const
{ return sect().file().translationUnitSource(); }
virtual const char* name() const { return _name; }
virtual uint64_t size() const { return _size; }
virtual uint64_t objectAddress() const { return _objAddress; }
virtual void copyRawContent(uint8_t buffer[]) const;
virtual const uint8_t* rawContentPointer() const { return contentPointer(); }
virtual unsigned long contentHash(const ld::IndirectBindingTable& ind) const
{ if ( _hash == 0 ) _hash = sect().contentHash(this, ind); return _hash; }
virtual bool canCoalesceWith(const ld::Atom& rhs, const ld::IndirectBindingTable& ind) const
{ return sect().canCoalesceWith(this, rhs, ind); }
virtual ld::Fixup::iterator fixupsBegin() const { return machofile()._fixups.data() + _fixupsStartIndex; }
virtual ld::Fixup::iterator fixupsEnd() const { return machofile()._fixups.data() + (_fixupsStartIndex+_fixupsCount); }
virtual ld::Atom::UnwindInfo::iterator beginUnwind() const { return machofile()._unwindInfos.data() + _unwindInfoStartIndex; }
virtual ld::Atom::UnwindInfo::iterator endUnwind() const { return machofile()._unwindInfos.data() + (_unwindInfoStartIndex+_unwindInfoCount); }
virtual ld::Atom::LineInfo::iterator beginLineInfo() const{ return machofile()._lineInfos.data() + _lineInfoStartIndex; }
virtual ld::Atom::LineInfo::iterator endLineInfo() const { return machofile()._lineInfos.data() + (_lineInfoStartIndex+_lineInfoCount); }
virtual void setFile(const ld::File* f);
private:
enum { kFixupStartIndexBits = 32,
kLineInfoStartIndexBits = 32,
kUnwindInfoStartIndexBits = 24,
kFixupCountBits = 24,
kLineInfoCountBits = 12,
kUnwindInfoCountBits = 4
}; // must sum to 128
public:
// methods for all atoms from mach-o object file
Section<A>& sect() const { return (Section<A>&)section(); }
File<A>& machofile() const { return ((Section<A>*)(this->_section))->file(); }
void setFixupsRange(uint32_t s, uint32_t c);
void setUnwindInfoRange(uint32_t s, uint32_t c);
void extendUnwindInfoRange();
void setLineInfoRange(uint32_t s, uint32_t c);
bool roomForMoreLineInfoCount() { return (_lineInfoCount < ((1<<kLineInfoCountBits)-1)); }
void incrementLineInfoCount() { assert(roomForMoreLineInfoCount()); ++_lineInfoCount; }
void incrementFixupCount() { if (_fixupsCount == ((1 << kFixupCountBits)-1)) { throwf("too may fixups in %s", name()); } ++_fixupsCount; }
const uint8_t* contentPointer() const;
uint32_t fixupCount() const { return _fixupsCount; }
void verifyAlignment(const macho_section<typename A::P>&) const;
typedef typename A::P P;
typedef typename A::P::E E;
typedef typename A::P::uint_t pint_t;
// constuct via all attributes
Atom(Section<A>& sct, const char* nm, pint_t addr, uint64_t sz,
ld::Atom::Definition d, ld::Atom::Combine c, ld::Atom::Scope s,
ld::Atom::ContentType ct, ld::Atom::SymbolTableInclusion i,
bool dds, bool thumb, bool al, ld::Atom::Alignment a)
: ld::Atom((ld::Section&)sct, d, c, s, ct, i, dds, thumb, al, a),
_size(sz), _objAddress(addr), _name(nm), _hash(0),
_fixupsStartIndex(0), _lineInfoStartIndex(0),
_unwindInfoStartIndex(0), _fixupsCount(0),
_lineInfoCount(0), _unwindInfoCount(0) { }
// construct via symbol table entry
Atom(Section<A>& sct, Parser<A>& parser, const macho_nlist<P>& sym,
uint64_t sz, bool alias=false)
: ld::Atom((ld::Section&)sct, parser.definitionFromSymbol(sym),
parser.combineFromSymbol(sym), parser.scopeFromSymbol(sym),
parser.resolverFromSymbol(sym) ? ld::Atom::typeResolver : sct.contentType(),
parser.inclusionFromSymbol(sym),
(parser.dontDeadStripFromSymbol(sym) && !sct.dontDeadStripIfReferencesLive()) || sct.dontDeadStrip(),
parser.isThumbFromSymbol(sym), alias,
sct.alignmentForAddress(sym.n_value()),
parser.coldFromSymbol(sym)),
_size(sz), _objAddress(sym.n_value()),
_name(parser.nameFromSymbol(sym)), _hash(0),
_fixupsStartIndex(0), _lineInfoStartIndex(0),
_unwindInfoStartIndex(0), _fixupsCount(0),
_lineInfoCount(0), _unwindInfoCount(0) {
// <rdar://problem/6783167> support auto-hidden weak symbols
if ( _scope == ld::Atom::scopeGlobal &&
(sym.n_desc() & (N_WEAK_DEF|N_WEAK_REF)) == (N_WEAK_DEF|N_WEAK_REF) )
this->setAutoHide();
this->verifyAlignment(*sct.machoSection());
if ( sct.dontDeadStripIfReferencesLive() )
this->setDontDeadStripIfReferencesLive();
}
private:
friend class Parser<A>;
friend class Section<A>;
friend class CStringSection<A>;
friend class AbsoluteSymbolSection<A>;
pint_t _size;
pint_t _objAddress;
const char* _name;
mutable unsigned long _hash;
uint64_t _fixupsStartIndex : kFixupStartIndexBits,
_lineInfoStartIndex : kLineInfoStartIndexBits,
_unwindInfoStartIndex : kUnwindInfoStartIndexBits,
_fixupsCount : kFixupCountBits,
_lineInfoCount : kLineInfoCountBits,
_unwindInfoCount : kUnwindInfoCountBits;
static ld::Map<const ld::Atom*, const ld::File*> _s_fileOverride;
};
template <typename A>
ld::Map<const ld::Atom*, const ld::File*> Atom<A>::_s_fileOverride;
template <typename A>
void Atom<A>::setFile(const ld::File* f) {
_s_fileOverride[this] = f;
}
template <typename A>
const ld::File* Atom<A>::file() const
{
auto pos = _s_fileOverride.find(this);
if ( pos != _s_fileOverride.end() )
return pos->second;
return §().file();
}
template <typename A>
void Atom<A>::setFixupsRange(uint32_t startIndex, uint32_t count)
{
if ( count >= (1 << kFixupCountBits) )
throwf("too many fixups in function %s", this->name());
if ( startIndex >= (1 << kFixupStartIndexBits) )
throwf("too many fixups in file");
assert(((startIndex+count) <= sect().file()._fixups.size()) && "fixup index out of range");
_fixupsStartIndex = startIndex;
_fixupsCount = count;
}
template <typename A>
void Atom<A>::setUnwindInfoRange(uint32_t startIndex, uint32_t count)
{
if ( count >= (1 << kUnwindInfoCountBits) )
throwf("too many compact unwind infos in function %s", this->name());
if ( startIndex >= (1 << kUnwindInfoStartIndexBits) )
throwf("too many compact unwind infos (%d) in file", startIndex);
assert((startIndex+count) <= sect().file()._unwindInfos.size() && "unwindinfo index out of range");
_unwindInfoStartIndex = startIndex;
_unwindInfoCount = count;
}
template <typename A>
void Atom<A>::extendUnwindInfoRange()
{
if ( _unwindInfoCount+1 >= (1 << kUnwindInfoCountBits) )
throwf("too many compact unwind infos in function %s", this->name());
_unwindInfoCount += 1;
}
template <typename A>
void Atom<A>::setLineInfoRange(uint32_t startIndex, uint32_t count)
{
assert((count < (1 << kLineInfoCountBits)) && "too many line infos");
assert((startIndex+count) < sect().file()._lineInfos.size() && "line info index out of range");
_lineInfoStartIndex = startIndex;
_lineInfoCount = count;
}
template <typename A>
const uint8_t* Atom<A>::contentPointer() const
{
const macho_section<P>* sct = this->sect().machoSection();
if ( this->_objAddress > sct->addr() + sct->size() )
throwf("malformed .o file, symbol has address 0x%0llX which is outside range of its section", (uint64_t)this->_objAddress);
uint32_t fileOffset = sct->offset() - sct->addr() + this->_objAddress;
return this->sect().file().fileContent()+fileOffset;
}
template <typename A>
void Atom<A>::copyRawContent(uint8_t buffer[]) const
{
// copy base bytes
if ( this->contentType() == ld::Atom::typeZeroFill ) {
bzero(buffer, _size);
}
else if ( _size != 0 ) {
memcpy(buffer, this->contentPointer(), _size);
}
}
template <>
void Atom<arm>::verifyAlignment(const macho_section<P>&) const
{
if ( (this->section().type() == ld::Section::typeCode) && ! isThumb() ) {
if ( ((_objAddress % 4) != 0) || (this->alignment().powerOf2 < 2) )
warning("ARM function not 4-byte aligned: %s from %s", this->name(), this->file()->path());
}
}
#if SUPPORT_ARCH_arm64
template <>
void Atom<arm64>::verifyAlignment(const macho_section<P>& sect) const
{
if ( (this->section().type() == ld::Section::typeCode) && (sect.size() != 0) ) {
if ( ((_objAddress % 4) != 0) || (this->alignment().powerOf2 < 2) )
warning("arm64 function not 4-byte aligned: %s from %s", this->name(), this->file()->path());
}
}
#endif
#if SUPPORT_ARCH_arm64_32
template <>
void Atom<arm64_32>::verifyAlignment(const macho_section<P>& sect) const
{
if ( (this->section().type() == ld::Section::typeCode) && (sect.size() != 0) ) {
if ( ((_objAddress % 4) != 0) || (this->alignment().powerOf2 < 2) )
warning("arm64 function not 4-byte aligned: %s from %s", this->name(), this->file()->path());
}
}
#endif
template <typename A>
void Atom<A>::verifyAlignment(const macho_section<P>&) const
{
}
class AliasAtom : public ld::Atom
{
public:
AliasAtom(const char* name, bool hidden, const ld::File* file, const char* aliasOfName) :
ld::Atom(_s_section, ld::Atom::definitionRegular, ld::Atom::combineNever,
(hidden ? ld::Atom::scopeLinkageUnit : ld::Atom::scopeGlobal),
ld::Atom::typeUnclassified, ld::Atom::symbolTableIn,
false, false, true, 0),
_file(file),
_name(name),
_fixup(0, ld::Fixup::k1of1, ld::Fixup::kindNoneFollowOn, ld::Fixup::bindingByNameUnbound, aliasOfName) { }
virtual const ld::File* file() const { return _file; }
virtual const char* translationUnitSource() const
{ return NULL; }
virtual const char* name() const { return _name; }
virtual uint64_t size() const { return 0; }
virtual uint64_t objectAddress() const { return 0; }
virtual void copyRawContent(uint8_t buffer[]) const { }
virtual ld::Fixup::iterator fixupsBegin() const { return &((ld::Fixup*)&_fixup)[0]; }
virtual ld::Fixup::iterator fixupsEnd() const { return &((ld::Fixup*)&_fixup)[1]; }
private:
static ld::Section _s_section;