1 // ehdr_start_test.cc -- test for __ehdr_start linker-defined symbol. 2 3 // Copyright (C) 2014 Free Software Foundation, Inc. 4 // Written by Cary Coutant <ccoutant (at) google.com>. 5 6 // This file is part of gold. 7 8 // This program is free software; you can redistribute it and/or modify 9 // it under the terms of the GNU General Public License as published by 10 // the Free Software Foundation; either version 3 of the License, or 11 // (at your option) any later version. 12 13 // This program is distributed in the hope that it will be useful, 14 // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 // GNU General Public License for more details. 17 18 // You should have received a copy of the GNU General Public License 19 // along with this program; if not, write to the Free Software 20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, 21 // MA 02110-1301, USA. 22 23 // The goal of this program is to produce as many different types of 24 // relocations as we can in a stand-alone program that does not use 25 // TLS. This program is compiled without optimization. 26 27 #include "config.h" 28 29 #include <cassert> 30 #include <cstdio> 31 32 #include "elfcpp.h" 33 34 #ifdef EHDR_START_WEAK 35 #define WEAK_ATTR __attribute__ ((weak)) 36 #else 37 #define WEAK_ATTR 38 #endif 39 40 extern char __ehdr_start[] WEAK_ATTR; 41 42 int 43 main() { 44 printf("&__ehdr_start = %p\n", &__ehdr_start); 45 46 #ifdef EHDR_START_UNDEF 47 assert(&__ehdr_start == 0); 48 #else 49 assert(&__ehdr_start != NULL); 50 51 printf("ELF header: \\x%02x%c%c%c\n", __ehdr_start[0], __ehdr_start[1], 52 __ehdr_start[2], __ehdr_start[3]); 53 #ifdef EHDR_START_USER_DEF 54 assert(__ehdr_start[0] == 'a' 55 && __ehdr_start[1] == 'b' 56 && __ehdr_start[2] == 'c' 57 && __ehdr_start[3] == 'd'); 58 #else 59 assert(__ehdr_start[elfcpp::EI_MAG0] == elfcpp::ELFMAG0 60 && __ehdr_start[elfcpp::EI_MAG1] == elfcpp::ELFMAG1 61 && __ehdr_start[elfcpp::EI_MAG2] == elfcpp::ELFMAG2 62 && __ehdr_start[elfcpp::EI_MAG3] == elfcpp::ELFMAG3); 63 #endif 64 #endif 65 66 return 0; 67 } 68