script_test_2.cc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // script_test_2.cc -- linker script test 2 for gold -*- C++ -*-
  2. // Copyright (C) 2008-2015 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[];
  24. extern char start_test_area_1[];
  25. extern char start_data[];
  26. extern char end_data[];
  27. extern char start_fill[];
  28. extern char end_fill[];
  29. extern char end_test_area[];
  30. extern char test_addr[];
  31. extern char test_addr_alias[];
  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) == 0x20000010);
  37. // We should see the string from script_test_2b.o next. The
  38. // subalign should move it up to 0x20000020.
  39. for (int i = 0; i < 16; ++i)
  40. assert(start_test_area_1[i] == 0);
  41. assert(strcmp(start_test_area_1 + 16, "test bb") == 0);
  42. // Next the string from script_test_2a.o, after the subalign.
  43. for (int i = 16 + 7; i < 48; ++i)
  44. assert(start_test_area_1[i] == 0);
  45. assert(strcmp(start_test_area_1 + 48, "test aa") == 0);
  46. // Move four bytes forward to start_data.
  47. assert(reinterpret_cast<uintptr_t>(start_test_area_1 + 48 + 8 + 4)
  48. == reinterpret_cast<uintptr_t>(start_data));
  49. assert(memcmp(start_data, "\1\2\0\4\0\0\0\010\0\0\0\0\0\0\0", 15) == 0
  50. || memcmp(start_data, "\1\0\2\0\0\0\4\0\0\0\0\0\0\0\010", 15) == 0);
  51. assert(end_data == start_data + 15);
  52. // Check that FILL works as expected.
  53. assert(start_fill == end_data);
  54. assert(memcmp(start_fill, "\x12\x34\x56\x78\x12\x34\x56\0", 8) == 0);
  55. assert(end_fill == start_fill + 8);
  56. assert(end_test_area == end_fill);
  57. assert(test_addr == start_test_area_1);
  58. assert(test_addr_alias == test_addr);
  59. }