xref: /aosp_15_r20/art/compiler/linker/linker_patch_test.cc (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker /*
2*795d594fSAndroid Build Coastguard Worker  * Copyright (C) 2017 The Android Open Source Project
3*795d594fSAndroid Build Coastguard Worker  *
4*795d594fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*795d594fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*795d594fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*795d594fSAndroid Build Coastguard Worker  *
8*795d594fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*795d594fSAndroid Build Coastguard Worker  *
10*795d594fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*795d594fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*795d594fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*795d594fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*795d594fSAndroid Build Coastguard Worker  * limitations under the License.
15*795d594fSAndroid Build Coastguard Worker  */
16*795d594fSAndroid Build Coastguard Worker 
17*795d594fSAndroid Build Coastguard Worker #include <gtest/gtest.h>
18*795d594fSAndroid Build Coastguard Worker 
19*795d594fSAndroid Build Coastguard Worker #include "base/macros.h"
20*795d594fSAndroid Build Coastguard Worker #include "linker_patch.h"
21*795d594fSAndroid Build Coastguard Worker 
22*795d594fSAndroid Build Coastguard Worker namespace art HIDDEN {
23*795d594fSAndroid Build Coastguard Worker namespace linker {
24*795d594fSAndroid Build Coastguard Worker 
TEST(LinkerPatch,LinkerPatchOperators)25*795d594fSAndroid Build Coastguard Worker TEST(LinkerPatch, LinkerPatchOperators) {
26*795d594fSAndroid Build Coastguard Worker   const DexFile* dex_file1 = reinterpret_cast<const DexFile*>(1);
27*795d594fSAndroid Build Coastguard Worker   const DexFile* dex_file2 = reinterpret_cast<const DexFile*>(2);
28*795d594fSAndroid Build Coastguard Worker   LinkerPatch patches[] = {
29*795d594fSAndroid Build Coastguard Worker       LinkerPatch::IntrinsicReferencePatch(16u, 3000u, 1000u),
30*795d594fSAndroid Build Coastguard Worker       LinkerPatch::IntrinsicReferencePatch(16u, 3001u, 1000u),
31*795d594fSAndroid Build Coastguard Worker       LinkerPatch::IntrinsicReferencePatch(16u, 3000u, 1001u),
32*795d594fSAndroid Build Coastguard Worker       LinkerPatch::IntrinsicReferencePatch(16u, 3001u, 1001u),
33*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3000u, 1000u),
34*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3001u, 1000u),
35*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3000u, 1001u),
36*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3001u, 1001u),  // Index 7.
37*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeMethodPatch(16u, dex_file2, 3000u, 1000u),
38*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeMethodPatch(16u, dex_file2, 3001u, 1000u),
39*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeMethodPatch(16u, dex_file2, 3000u, 1001u),
40*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeMethodPatch(16u, dex_file2, 3001u, 1001u),
41*795d594fSAndroid Build Coastguard Worker       LinkerPatch::MethodBssEntryPatch(16u, dex_file1, 3000u, 1000u),
42*795d594fSAndroid Build Coastguard Worker       LinkerPatch::MethodBssEntryPatch(16u, dex_file1, 3001u, 1000u),
43*795d594fSAndroid Build Coastguard Worker       LinkerPatch::MethodBssEntryPatch(16u, dex_file1, 3000u, 1001u),
44*795d594fSAndroid Build Coastguard Worker       LinkerPatch::MethodBssEntryPatch(16u, dex_file1, 3001u, 1001u),
45*795d594fSAndroid Build Coastguard Worker       LinkerPatch::MethodBssEntryPatch(16u, dex_file2, 3000u, 1000u),
46*795d594fSAndroid Build Coastguard Worker       LinkerPatch::MethodBssEntryPatch(16u, dex_file2, 3001u, 1000u),
47*795d594fSAndroid Build Coastguard Worker       LinkerPatch::MethodBssEntryPatch(16u, dex_file2, 3000u, 1001u),
48*795d594fSAndroid Build Coastguard Worker       LinkerPatch::MethodBssEntryPatch(16u, dex_file2, 3001u, 1001u),
49*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeCodePatch(16u, dex_file1, 1000u),
50*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeCodePatch(16u, dex_file1, 1001u),
51*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeCodePatch(16u, dex_file2, 1000u),
52*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeCodePatch(16u, dex_file2, 1001u),
53*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeTypePatch(16u, dex_file1, 3000u, 1000u),
54*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeTypePatch(16u, dex_file1, 3001u, 1000u),
55*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeTypePatch(16u, dex_file1, 3000u, 1001u),
56*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeTypePatch(16u, dex_file1, 3001u, 1001u),
57*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeTypePatch(16u, dex_file2, 3000u, 1000u),
58*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeTypePatch(16u, dex_file2, 3001u, 1000u),
59*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeTypePatch(16u, dex_file2, 3000u, 1001u),
60*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeTypePatch(16u, dex_file2, 3001u, 1001u),
61*795d594fSAndroid Build Coastguard Worker       LinkerPatch::TypeBssEntryPatch(16u, dex_file1, 3000u, 1000u),
62*795d594fSAndroid Build Coastguard Worker       LinkerPatch::TypeBssEntryPatch(16u, dex_file1, 3001u, 1000u),
63*795d594fSAndroid Build Coastguard Worker       LinkerPatch::TypeBssEntryPatch(16u, dex_file1, 3000u, 1001u),
64*795d594fSAndroid Build Coastguard Worker       LinkerPatch::TypeBssEntryPatch(16u, dex_file1, 3001u, 1001u),
65*795d594fSAndroid Build Coastguard Worker       LinkerPatch::TypeBssEntryPatch(16u, dex_file2, 3000u, 1000u),
66*795d594fSAndroid Build Coastguard Worker       LinkerPatch::TypeBssEntryPatch(16u, dex_file2, 3001u, 1000u),
67*795d594fSAndroid Build Coastguard Worker       LinkerPatch::TypeBssEntryPatch(16u, dex_file2, 3000u, 1001u),
68*795d594fSAndroid Build Coastguard Worker       LinkerPatch::TypeBssEntryPatch(16u, dex_file2, 3001u, 1001u),
69*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeStringPatch(16u, dex_file1, 3000u, 1000u),
70*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeStringPatch(16u, dex_file1, 3001u, 1000u),
71*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeStringPatch(16u, dex_file1, 3000u, 1001u),
72*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeStringPatch(16u, dex_file1, 3001u, 1001u),
73*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeStringPatch(16u, dex_file2, 3000u, 1000u),
74*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeStringPatch(16u, dex_file2, 3001u, 1000u),
75*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeStringPatch(16u, dex_file2, 3000u, 1001u),
76*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeStringPatch(16u, dex_file2, 3001u, 1001u),
77*795d594fSAndroid Build Coastguard Worker       LinkerPatch::StringBssEntryPatch(16u, dex_file1, 3000u, 1000u),
78*795d594fSAndroid Build Coastguard Worker       LinkerPatch::StringBssEntryPatch(16u, dex_file1, 3001u, 1000u),
79*795d594fSAndroid Build Coastguard Worker       LinkerPatch::StringBssEntryPatch(16u, dex_file1, 3000u, 1001u),
80*795d594fSAndroid Build Coastguard Worker       LinkerPatch::StringBssEntryPatch(16u, dex_file1, 3001u, 1001u),
81*795d594fSAndroid Build Coastguard Worker       LinkerPatch::StringBssEntryPatch(16u, dex_file2, 3000u, 1000u),
82*795d594fSAndroid Build Coastguard Worker       LinkerPatch::StringBssEntryPatch(16u, dex_file2, 3001u, 1000u),
83*795d594fSAndroid Build Coastguard Worker       LinkerPatch::StringBssEntryPatch(16u, dex_file2, 3000u, 1001u),
84*795d594fSAndroid Build Coastguard Worker       LinkerPatch::StringBssEntryPatch(16u, dex_file2, 3001u, 1001u),
85*795d594fSAndroid Build Coastguard Worker       LinkerPatch::BakerReadBarrierBranchPatch(16u, 0u, 0u),
86*795d594fSAndroid Build Coastguard Worker       LinkerPatch::BakerReadBarrierBranchPatch(16u, 0u, 1u),
87*795d594fSAndroid Build Coastguard Worker       LinkerPatch::BakerReadBarrierBranchPatch(16u, 1u, 0u),
88*795d594fSAndroid Build Coastguard Worker       LinkerPatch::BakerReadBarrierBranchPatch(16u, 1u, 1u),
89*795d594fSAndroid Build Coastguard Worker 
90*795d594fSAndroid Build Coastguard Worker       LinkerPatch::IntrinsicReferencePatch(32u, 3000u, 1000u),
91*795d594fSAndroid Build Coastguard Worker       LinkerPatch::IntrinsicReferencePatch(32u, 3001u, 1000u),
92*795d594fSAndroid Build Coastguard Worker       LinkerPatch::IntrinsicReferencePatch(32u, 3000u, 1001u),
93*795d594fSAndroid Build Coastguard Worker       LinkerPatch::IntrinsicReferencePatch(32u, 3001u, 1001u),
94*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeMethodPatch(32u, dex_file1, 3000u, 1000u),
95*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeMethodPatch(32u, dex_file1, 3001u, 1000u),
96*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeMethodPatch(32u, dex_file1, 3000u, 1001u),
97*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeMethodPatch(32u, dex_file1, 3001u, 1001u),
98*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeMethodPatch(32u, dex_file2, 3000u, 1000u),
99*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeMethodPatch(32u, dex_file2, 3001u, 1000u),
100*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeMethodPatch(32u, dex_file2, 3000u, 1001u),
101*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeMethodPatch(32u, dex_file2, 3001u, 1001u),
102*795d594fSAndroid Build Coastguard Worker       LinkerPatch::MethodBssEntryPatch(32u, dex_file1, 3000u, 1000u),
103*795d594fSAndroid Build Coastguard Worker       LinkerPatch::MethodBssEntryPatch(32u, dex_file1, 3001u, 1000u),
104*795d594fSAndroid Build Coastguard Worker       LinkerPatch::MethodBssEntryPatch(32u, dex_file1, 3000u, 1001u),
105*795d594fSAndroid Build Coastguard Worker       LinkerPatch::MethodBssEntryPatch(32u, dex_file1, 3001u, 1001u),
106*795d594fSAndroid Build Coastguard Worker       LinkerPatch::MethodBssEntryPatch(32u, dex_file2, 3000u, 1000u),
107*795d594fSAndroid Build Coastguard Worker       LinkerPatch::MethodBssEntryPatch(32u, dex_file2, 3001u, 1000u),
108*795d594fSAndroid Build Coastguard Worker       LinkerPatch::MethodBssEntryPatch(32u, dex_file2, 3000u, 1001u),
109*795d594fSAndroid Build Coastguard Worker       LinkerPatch::MethodBssEntryPatch(32u, dex_file2, 3001u, 1001u),
110*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeCodePatch(32u, dex_file1, 1000u),
111*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeCodePatch(32u, dex_file1, 1001u),
112*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeCodePatch(32u, dex_file2, 1000u),
113*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeCodePatch(32u, dex_file2, 1001u),
114*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeTypePatch(32u, dex_file1, 3000u, 1000u),
115*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeTypePatch(32u, dex_file1, 3001u, 1000u),
116*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeTypePatch(32u, dex_file1, 3000u, 1001u),
117*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeTypePatch(32u, dex_file1, 3001u, 1001u),
118*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeTypePatch(32u, dex_file2, 3000u, 1000u),
119*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeTypePatch(32u, dex_file2, 3001u, 1000u),
120*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeTypePatch(32u, dex_file2, 3000u, 1001u),
121*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeTypePatch(32u, dex_file2, 3001u, 1001u),
122*795d594fSAndroid Build Coastguard Worker       LinkerPatch::TypeBssEntryPatch(32u, dex_file1, 3000u, 1000u),
123*795d594fSAndroid Build Coastguard Worker       LinkerPatch::TypeBssEntryPatch(32u, dex_file1, 3001u, 1000u),
124*795d594fSAndroid Build Coastguard Worker       LinkerPatch::TypeBssEntryPatch(32u, dex_file1, 3000u, 1001u),
125*795d594fSAndroid Build Coastguard Worker       LinkerPatch::TypeBssEntryPatch(32u, dex_file1, 3001u, 1001u),
126*795d594fSAndroid Build Coastguard Worker       LinkerPatch::TypeBssEntryPatch(32u, dex_file2, 3000u, 1000u),
127*795d594fSAndroid Build Coastguard Worker       LinkerPatch::TypeBssEntryPatch(32u, dex_file2, 3001u, 1000u),
128*795d594fSAndroid Build Coastguard Worker       LinkerPatch::TypeBssEntryPatch(32u, dex_file2, 3000u, 1001u),
129*795d594fSAndroid Build Coastguard Worker       LinkerPatch::TypeBssEntryPatch(32u, dex_file2, 3001u, 1001u),
130*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeStringPatch(32u, dex_file1, 3000u, 1000u),
131*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeStringPatch(32u, dex_file1, 3001u, 1000u),
132*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeStringPatch(32u, dex_file1, 3000u, 1001u),
133*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeStringPatch(32u, dex_file1, 3001u, 1001u),
134*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeStringPatch(32u, dex_file2, 3000u, 1000u),
135*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeStringPatch(32u, dex_file2, 3001u, 1000u),
136*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeStringPatch(32u, dex_file2, 3000u, 1001u),
137*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeStringPatch(32u, dex_file2, 3001u, 1001u),
138*795d594fSAndroid Build Coastguard Worker       LinkerPatch::StringBssEntryPatch(32u, dex_file1, 3000u, 1000u),
139*795d594fSAndroid Build Coastguard Worker       LinkerPatch::StringBssEntryPatch(32u, dex_file1, 3001u, 1000u),
140*795d594fSAndroid Build Coastguard Worker       LinkerPatch::StringBssEntryPatch(32u, dex_file1, 3000u, 1001u),
141*795d594fSAndroid Build Coastguard Worker       LinkerPatch::StringBssEntryPatch(32u, dex_file1, 3001u, 1001u),
142*795d594fSAndroid Build Coastguard Worker       LinkerPatch::StringBssEntryPatch(32u, dex_file2, 3000u, 1000u),
143*795d594fSAndroid Build Coastguard Worker       LinkerPatch::StringBssEntryPatch(32u, dex_file2, 3001u, 1000u),
144*795d594fSAndroid Build Coastguard Worker       LinkerPatch::StringBssEntryPatch(32u, dex_file2, 3000u, 1001u),
145*795d594fSAndroid Build Coastguard Worker       LinkerPatch::StringBssEntryPatch(32u, dex_file2, 3001u, 1001u),
146*795d594fSAndroid Build Coastguard Worker       LinkerPatch::BakerReadBarrierBranchPatch(32u, 0u, 0u),
147*795d594fSAndroid Build Coastguard Worker       LinkerPatch::BakerReadBarrierBranchPatch(32u, 0u, 1u),
148*795d594fSAndroid Build Coastguard Worker       LinkerPatch::BakerReadBarrierBranchPatch(32u, 1u, 0u),
149*795d594fSAndroid Build Coastguard Worker       LinkerPatch::BakerReadBarrierBranchPatch(32u, 1u, 1u),
150*795d594fSAndroid Build Coastguard Worker 
151*795d594fSAndroid Build Coastguard Worker       LinkerPatch::RelativeMethodPatch(16u, dex_file1, 3001u, 1001u),  // Same as patch at index 7.
152*795d594fSAndroid Build Coastguard Worker   };
153*795d594fSAndroid Build Coastguard Worker   constexpr size_t last_index = arraysize(patches) - 1u;
154*795d594fSAndroid Build Coastguard Worker 
155*795d594fSAndroid Build Coastguard Worker   for (size_t i = 0; i != arraysize(patches); ++i) {
156*795d594fSAndroid Build Coastguard Worker     for (size_t j = 0; j != arraysize(patches); ++j) {
157*795d594fSAndroid Build Coastguard Worker       bool expected = (i != last_index ? i : 7u) == (j != last_index ? j : 7u);
158*795d594fSAndroid Build Coastguard Worker       EXPECT_EQ(expected, patches[i] == patches[j]) << i << " " << j;
159*795d594fSAndroid Build Coastguard Worker     }
160*795d594fSAndroid Build Coastguard Worker   }
161*795d594fSAndroid Build Coastguard Worker 
162*795d594fSAndroid Build Coastguard Worker   for (size_t i = 0; i != arraysize(patches); ++i) {
163*795d594fSAndroid Build Coastguard Worker     for (size_t j = 0; j != arraysize(patches); ++j) {
164*795d594fSAndroid Build Coastguard Worker       bool expected = (i != last_index ? i : 7u) < (j != last_index ? j : 7u);
165*795d594fSAndroid Build Coastguard Worker       EXPECT_EQ(expected, patches[i] < patches[j]) << i << " " << j;
166*795d594fSAndroid Build Coastguard Worker     }
167*795d594fSAndroid Build Coastguard Worker   }
168*795d594fSAndroid Build Coastguard Worker }
169*795d594fSAndroid Build Coastguard Worker 
170*795d594fSAndroid Build Coastguard Worker }  // namespace linker
171*795d594fSAndroid Build Coastguard Worker }  // namespace art
172