Home | History | Annotate | Download | only in libs
      1 /*
      2  * Copyright (C) 2018 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 extern "C" int getRandomNumber();
     18 
     19 class B {
     20 public:
     21   virtual int getBiggerRandomNumber() {
     22     // Call to the other library.
     23     return getRandomNumber() * 2;
     24   }
     25 
     26   virtual ~B() {}
     27 };
     28 
     29 B b;
     30 
     31 // nested macros to make it easy to define a large amount of read-only data
     32 // which will require relocation.
     33 #define B_16 &b, &b, &b, &b, &b, &b, &b, &b, &b, &b, &b, &b, &b, &b, &b, &b,
     34 #define B_128 B_16 B_16 B_16 B_16 B_16 B_16 B_16 B_16
     35 #define B_1024 B_128 B_128 B_128 B_128 B_128 B_128 B_128 B_128
     36 
     37 extern "C" B* const lots_more_relro[] = {
     38   B_1024 B_1024 B_1024 B_1024 B_1024 B_1024 B_1024 B_1024
     39 };
     40 
     41 extern "C" int getBiggerRandomNumber() {
     42   // access the relro section (twice, in fact, once for the pointer, and once
     43   // for the vtable of B) to check it's actually there.
     44   return lots_more_relro[0]->getBiggerRandomNumber();
     45 }
     46