@@ -160,13 +160,14 @@ TEST_P(BinaryContextTester, FlushPendingRelocJUMP26) {
160160TEST_P (BinaryContextTester, BaseAddress) {
161161 // Check that base address calculation is correct for a binary with the
162162 // 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 };
164165 BC->SegmentMapInfo [0x10e8d2b4 ] =
165- SegmentInfo{0x10e8d2b4 , 0x3952faec , 0x10e8c2b4 , 0x3952faec , 0x1000 };
166+ SegmentInfo{0x10e8d2b4 , 0x3952faec , 0x10e8c2b4 , 0x3952faec , 0x1000 , true };
166167 BC->SegmentMapInfo [0x4a3bddc0 ] =
167- SegmentInfo{0x4a3bddc0 , 0x148e828 , 0x4a3bbdc0 , 0x148e828 , 0x1000 };
168+ SegmentInfo{0x4a3bddc0 , 0x148e828 , 0x4a3bbdc0 , 0x148e828 , 0x1000 , true };
168169 BC->SegmentMapInfo [0x4b84d5e8 ] =
169- SegmentInfo{0x4b84d5e8 , 0x294f830 , 0x4b84a5e8 , 0x3d3820 , 0x1000 };
170+ SegmentInfo{0x4b84d5e8 , 0x294f830 , 0x4b84a5e8 , 0x3d3820 , 0x1000 , true };
170171
171172 std::optional<uint64_t > BaseAddress =
172173 BC->getBaseAddressForMapping (0x7f13f5556000 , 0x10e8c000 );
@@ -181,13 +182,13 @@ TEST_P(BinaryContextTester, BaseAddress2) {
181182 // Check that base address calculation is correct for a binary if the
182183 // alignment in ELF file are different from pagesize.
183184 // 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 };
185186 BC->SegmentMapInfo [0x31860 ] =
186- SegmentInfo{0x31860 , 0x370 , 0x21860 , 0x370 , 0x10000 };
187+ SegmentInfo{0x31860 , 0x370 , 0x21860 , 0x370 , 0x10000 , true };
187188 BC->SegmentMapInfo [0x41c20 ] =
188- SegmentInfo{0x41c20 , 0x1f8 , 0x21c20 , 0x1f8 , 0x10000 };
189+ SegmentInfo{0x41c20 , 0x1f8 , 0x21c20 , 0x1f8 , 0x10000 , true };
189190 BC->SegmentMapInfo [0x54e18 ] =
190- SegmentInfo{0x54e18 , 0x51 , 0x24e18 , 0x51 , 0x10000 };
191+ SegmentInfo{0x54e18 , 0x51 , 0x24e18 , 0x51 , 0x10000 , true };
191192
192193 std::optional<uint64_t > BaseAddress =
193194 BC->getBaseAddressForMapping (0xaaaaea444000 , 0x21000 );
@@ -197,3 +198,22 @@ TEST_P(BinaryContextTester, BaseAddress2) {
197198 BaseAddress = BC->getBaseAddressForMapping (0xaaaaea444000 , 0x11000 );
198199 ASSERT_FALSE (BaseAddress.has_value ());
199200}
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