script_test_2.cc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // script_test_2.cc -- linker script test 2 for gold -*- C++ -*-
  2. // Copyright (C) 2008-2022 Free Software Foundation, Inc.
  3. // Written by Ian Lance Taylor <iant@google.com>.
  4. // This file is part of gold.
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 3 of the License, or
  8. // (at your option) any later version.
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. // MA 02110-1301, USA.
  17. // A test of some uses of the SECTIONS clause. Look at
  18. // script_test_2.t to make sense of this test.
  19. #include <cassert>
  20. #include <cstddef>
  21. #include <cstring>
  22. #include <stdint.h>
  23. extern char start_test_area[] __attribute__((__aligned__(1)));
  24. extern char start_test_area_1[] __attribute__((__aligned__(1)));
  25. extern char start_data[] __attribute__((__aligned__(1)));
  26. extern char end_data[] __attribute__((__aligned__(1)));
  27. extern char start_fill[] __attribute__((__aligned__(1)));
  28. extern char end_fill[] __attribute__((__aligned__(1)));
  29. extern char end_test_area[] __attribute__((__aligned__(1)));
  30. extern char test_addr[] __attribute__((__aligned__(1)));
  31. extern char test_addr_alias[] __attribute__((__aligned__(1)));
  32. int
  33. main(int, char**)
  34. {
  35. assert(reinterpret_cast<uintptr_t>(start_test_area) == 0x20000001);
  36. assert(reinterpret_cast<uintptr_t>(start_test_area_1) == 0x20000020);
  37. assert(strcmp(start_test_area_1, "test bb") == 0);
  38. // Next the string from script_test_2a.o, after the subalign.
  39. for (int i = 7; i < 32; ++i)
  40. assert(start_test_area_1[i] == 0);
  41. assert(strcmp(start_test_area_1 + 32, "test aa") == 0);
  42. // Skip to start_data at relative offset 60.
  43. for (int i = 32 + 7; i < 60; ++i)
  44. assert(start_test_area_1[i] == 0);
  45. assert(reinterpret_cast<uintptr_t>(start_test_area_1 + 60)
  46. == reinterpret_cast<uintptr_t>(start_data));
  47. assert(memcmp(start_data, "\1\2\0\4\0\0\0\010\0\0\0\0\0\0\0", 15) == 0
  48. || memcmp(start_data, "\1\0\2\0\0\0\4\0\0\0\0\0\0\0\010", 15) == 0);
  49. assert(end_data == start_data + 15);
  50. // Check that FILL works as expected.
  51. assert(&start_fill[0] == &end_data[0]);
  52. assert(memcmp(start_fill, "\x12\x34\x56\x78\x12\x34\x56\0", 8) == 0);
  53. assert(end_fill == start_fill + 8);
  54. assert(&end_test_area[0] == &end_fill[0]);
  55. assert(&test_addr[0] == &start_test_area_1[0]);
  56. assert(&test_addr_alias[0] == &test_addr[0]);
  57. }