@@ -40,39 +40,45 @@ inline uint64_t bitField(uint64_t value, int right, int width, int left) {
40
40
// | | imm26 |
41
41
// +-----------+---------------------------------------------------+
42
42
43
- inline uint64_t encodeBranch26 (const Reloc &r, uint64_t base, uint64_t va) {
44
- checkInt (r, va, 28 );
43
+ inline void encodeBranch26 (uint32_t *loc, const Reloc &r, uint32_t base,
44
+ uint64_t va) {
45
+ checkInt (loc, r, va, 28 );
45
46
// Since branch destinations are 4-byte aligned, the 2 least-
46
47
// significant bits are 0. They are right shifted off the end.
47
- return ( base | bitField (va, 2 , 26 , 0 ));
48
+ llvm::support::endian::write32le (loc, base | bitField (va, 2 , 26 , 0 ));
48
49
}
49
50
50
- inline uint64_t encodeBranch26 (SymbolDiagnostic d, uint64_t base, uint64_t va) {
51
- checkInt (d, va, 28 );
52
- return (base | bitField (va, 2 , 26 , 0 ));
51
+ inline void encodeBranch26 (uint32_t *loc, SymbolDiagnostic d, uint32_t base,
52
+ uint64_t va) {
53
+ checkInt (loc, d, va, 28 );
54
+ llvm::support::endian::write32le (loc, base | bitField (va, 2 , 26 , 0 ));
53
55
}
54
56
55
57
// 30 29 23 5
56
58
// +-+---+---------+-------------------------------------+---------+
57
59
// | |ilo| | immhi | |
58
60
// +-+---+---------+-------------------------------------+---------+
59
61
60
- inline uint64_t encodePage21 (const Reloc &r, uint64_t base, uint64_t va) {
61
- checkInt (r, va, 35 );
62
- return (base | bitField (va, 12 , 2 , 29 ) | bitField (va, 14 , 19 , 5 ));
62
+ inline void encodePage21 (uint32_t *loc, const Reloc &r, uint32_t base,
63
+ uint64_t va) {
64
+ checkInt (loc, r, va, 35 );
65
+ llvm::support::endian::write32le (loc, base | bitField (va, 12 , 2 , 29 ) |
66
+ bitField (va, 14 , 19 , 5 ));
63
67
}
64
68
65
- inline uint64_t encodePage21 (SymbolDiagnostic d, uint64_t base, uint64_t va) {
66
- checkInt (d, va, 35 );
67
- return (base | bitField (va, 12 , 2 , 29 ) | bitField (va, 14 , 19 , 5 ));
69
+ inline void encodePage21 (uint32_t *loc, SymbolDiagnostic d, uint32_t base,
70
+ uint64_t va) {
71
+ checkInt (loc, d, va, 35 );
72
+ llvm::support::endian::write32le (loc, base | bitField (va, 12 , 2 , 29 ) |
73
+ bitField (va, 14 , 19 , 5 ));
68
74
}
69
75
70
76
// 21 10
71
77
// +-------------------+-----------------------+-------------------+
72
78
// | | imm12 | |
73
79
// +-------------------+-----------------------+-------------------+
74
80
75
- inline uint64_t encodePageOff12 (uint32_t base, uint64_t va) {
81
+ inline void encodePageOff12 (uint32_t *loc, uint32_t base, uint64_t va) {
76
82
int scale = 0 ;
77
83
if ((base & 0x3b00'0000 ) == 0x3900'0000 ) { // load/store
78
84
scale = base >> 30 ;
@@ -82,7 +88,8 @@ inline uint64_t encodePageOff12(uint32_t base, uint64_t va) {
82
88
83
89
// TODO(gkm): extract embedded addend and warn if != 0
84
90
// uint64_t addend = ((base & 0x003FFC00) >> 10);
85
- return (base | bitField (va, scale, 12 - scale, 10 ));
91
+ llvm::support::endian::write32le (loc,
92
+ base | bitField (va, scale, 12 - scale, 10 ));
86
93
}
87
94
88
95
inline uint64_t pageBits (uint64_t address) {
@@ -99,9 +106,9 @@ inline void writeStub(uint8_t *buf8, const uint32_t stubCode[3],
99
106
pageBits (in.stubs ->addr + sym.stubsIndex * stubCodeSize);
100
107
uint64_t lazyPointerVA =
101
108
in.lazyPointers ->addr + sym.stubsIndex * LP::wordSize;
102
- buf32[0 ] = encodePage21 ( {&sym, " stub" }, stubCode[0 ],
103
- pageBits (lazyPointerVA) - pcPageBits);
104
- buf32[1 ] = encodePageOff12 ( stubCode[1 ], lazyPointerVA);
109
+ encodePage21 (& buf32[0 ], {&sym, " stub" }, stubCode[0 ],
110
+ pageBits (lazyPointerVA) - pcPageBits);
111
+ encodePageOff12 (& buf32[1 ], stubCode[1 ], lazyPointerVA);
105
112
buf32[2 ] = stubCode[2 ];
106
113
}
107
114
@@ -114,15 +121,15 @@ inline void writeStubHelperHeader(uint8_t *buf8,
114
121
};
115
122
uint64_t loaderVA = in.imageLoaderCache ->getVA ();
116
123
SymbolDiagnostic d = {nullptr , " stub header helper" };
117
- buf32[0 ] = encodePage21 ( d, stubHelperHeaderCode[0 ],
118
- pageBits (loaderVA) - pcPageBits (0 ));
119
- buf32[1 ] = encodePageOff12 ( stubHelperHeaderCode[1 ], loaderVA);
124
+ encodePage21 (& buf32[0 ], d, stubHelperHeaderCode[0 ],
125
+ pageBits (loaderVA) - pcPageBits (0 ));
126
+ encodePageOff12 (& buf32[1 ], stubHelperHeaderCode[1 ], loaderVA);
120
127
buf32[2 ] = stubHelperHeaderCode[2 ];
121
128
uint64_t binderVA =
122
129
in.got ->addr + in.stubHelper ->stubBinder ->gotIndex * LP::wordSize;
123
- buf32[3 ] = encodePage21 ( d, stubHelperHeaderCode[3 ],
124
- pageBits (binderVA) - pcPageBits (3 ));
125
- buf32[4 ] = encodePageOff12 ( stubHelperHeaderCode[4 ], binderVA);
130
+ encodePage21 (& buf32[3 ], d, stubHelperHeaderCode[3 ],
131
+ pageBits (binderVA) - pcPageBits (3 ));
132
+ encodePageOff12 (& buf32[4 ], stubHelperHeaderCode[4 ], binderVA);
126
133
buf32[5 ] = stubHelperHeaderCode[5 ];
127
134
}
128
135
@@ -133,8 +140,8 @@ inline void writeStubHelperEntry(uint8_t *buf8,
133
140
auto pcVA = [entryVA](int i) { return entryVA + i * sizeof (uint32_t ); };
134
141
uint64_t stubHelperHeaderVA = in.stubHelper ->addr ;
135
142
buf32[0 ] = stubHelperEntryCode[0 ];
136
- buf32[1 ] = encodeBranch26 ( {&sym, " stub helper" }, stubHelperEntryCode[1 ],
137
- stubHelperHeaderVA - pcVA (1 ));
143
+ encodeBranch26 (& buf32[1 ], {&sym, " stub helper" }, stubHelperEntryCode[1 ],
144
+ stubHelperHeaderVA - pcVA (1 ));
138
145
buf32[2 ] = sym.lazyBindOffset ;
139
146
}
140
147
0 commit comments