@@ -160,13 +160,14 @@ TEST_P(BinaryContextTester, FlushPendingRelocJUMP26) {
160
160
TEST_P (BinaryContextTester, BaseAddress) {
161
161
// Check that base address calculation is correct for a binary with the
162
162
// following segment layout:
163
- BC->SegmentMapInfo [0 ] = SegmentInfo{0 , 0x10e8c2b4 , 0 , 0x10e8c2b4 , 0x1000 };
163
+ BC->SegmentMapInfo [0 ] =
164
+ SegmentInfo{0 , 0x10e8c2b4 , 0 , 0x10e8c2b4 , 0x1000 , true };
164
165
BC->SegmentMapInfo [0x10e8d2b4 ] =
165
- SegmentInfo{0x10e8d2b4 , 0x3952faec , 0x10e8c2b4 , 0x3952faec , 0x1000 };
166
+ SegmentInfo{0x10e8d2b4 , 0x3952faec , 0x10e8c2b4 , 0x3952faec , 0x1000 , true };
166
167
BC->SegmentMapInfo [0x4a3bddc0 ] =
167
- SegmentInfo{0x4a3bddc0 , 0x148e828 , 0x4a3bbdc0 , 0x148e828 , 0x1000 };
168
+ SegmentInfo{0x4a3bddc0 , 0x148e828 , 0x4a3bbdc0 , 0x148e828 , 0x1000 , true };
168
169
BC->SegmentMapInfo [0x4b84d5e8 ] =
169
- SegmentInfo{0x4b84d5e8 , 0x294f830 , 0x4b84a5e8 , 0x3d3820 , 0x1000 };
170
+ SegmentInfo{0x4b84d5e8 , 0x294f830 , 0x4b84a5e8 , 0x3d3820 , 0x1000 , true };
170
171
171
172
std::optional<uint64_t > BaseAddress =
172
173
BC->getBaseAddressForMapping (0x7f13f5556000 , 0x10e8c000 );
@@ -181,13 +182,13 @@ TEST_P(BinaryContextTester, BaseAddress2) {
181
182
// Check that base address calculation is correct for a binary if the
182
183
// alignment in ELF file are different from pagesize.
183
184
// The segment layout is as follows:
184
- BC->SegmentMapInfo [0 ] = SegmentInfo{0 , 0x2177c , 0 , 0x2177c , 0x10000 };
185
+ BC->SegmentMapInfo [0 ] = SegmentInfo{0 , 0x2177c , 0 , 0x2177c , 0x10000 , true };
185
186
BC->SegmentMapInfo [0x31860 ] =
186
- SegmentInfo{0x31860 , 0x370 , 0x21860 , 0x370 , 0x10000 };
187
+ SegmentInfo{0x31860 , 0x370 , 0x21860 , 0x370 , 0x10000 , true };
187
188
BC->SegmentMapInfo [0x41c20 ] =
188
- SegmentInfo{0x41c20 , 0x1f8 , 0x21c20 , 0x1f8 , 0x10000 };
189
+ SegmentInfo{0x41c20 , 0x1f8 , 0x21c20 , 0x1f8 , 0x10000 , true };
189
190
BC->SegmentMapInfo [0x54e18 ] =
190
- SegmentInfo{0x54e18 , 0x51 , 0x24e18 , 0x51 , 0x10000 };
191
+ SegmentInfo{0x54e18 , 0x51 , 0x24e18 , 0x51 , 0x10000 , true };
191
192
192
193
std::optional<uint64_t > BaseAddress =
193
194
BC->getBaseAddressForMapping (0xaaaaea444000 , 0x21000 );
@@ -197,3 +198,22 @@ TEST_P(BinaryContextTester, BaseAddress2) {
197
198
BaseAddress = BC->getBaseAddressForMapping (0xaaaaea444000 , 0x11000 );
198
199
ASSERT_FALSE (BaseAddress.has_value ());
199
200
}
201
+
202
+ TEST_P (BinaryContextTester, BaseAddressSegmentsSmallerThanAlignment) {
203
+ // Check that the correct segment is used to compute the base address
204
+ // when multiple segments are close together in the ELF file (closer
205
+ // than the required alignment in the process space).
206
+ // See https://github.com/llvm/llvm-project/issues/109384
207
+ BC->SegmentMapInfo [0 ] = SegmentInfo{0 , 0x1d1c , 0 , 0x1d1c , 0x10000 , false };
208
+ BC->SegmentMapInfo [0x11d40 ] =
209
+ SegmentInfo{0x11d40 , 0x11e0 , 0x1d40 , 0x11e0 , 0x10000 , true };
210
+ BC->SegmentMapInfo [0x22f20 ] =
211
+ SegmentInfo{0x22f20 , 0x10e0 , 0x2f20 , 0x1f0 , 0x10000 , false };
212
+ BC->SegmentMapInfo [0x33110 ] =
213
+ SegmentInfo{0x33110 , 0x89 , 0x3110 , 0x88 , 0x10000 , false };
214
+
215
+ std::optional<uint64_t > BaseAddress =
216
+ BC->getBaseAddressForMapping (0xaaaaaaab1000 , 0x1000 );
217
+ ASSERT_TRUE (BaseAddress.has_value ());
218
+ ASSERT_EQ (*BaseAddress, 0xaaaaaaaa0000ULL );
219
+ }
0 commit comments