script_test_12a.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* script_test_12a.c -- a test case for gold
  2. Copyright (C) 2015-2022 Free Software Foundation, Inc.
  3. Written by Cary Coutant <ccoutant@gmail.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. This tests linker script behavior, that gold distinguishes correctly
  18. between
  19. *(.x1) *(.x2) *(.x3)
  20. and
  21. *(.x1 .x2 .x3)
  22. in an input section spec. In the first case, the output section
  23. should contain all .x1 sections, followed by all .x2 sections,
  24. then all .x3 sections; i.e.:
  25. script_test_12a.o(.x1)
  26. script_test_12b.o(.x1)
  27. script_test_12a.o(.x2)
  28. script_test_12b.o(.x2)
  29. script_test_12a.o(.x3)
  30. script_test_12b.o(.x3)
  31. In the second case, the output section should interleave the
  32. .x1, .x2, and .x3 sections in the order seen; i.e.:
  33. script_test_12a.o(.x1)
  34. script_test_12a.o(.x2)
  35. script_test_12a.o(.x3)
  36. script_test_12b.o(.x1)
  37. script_test_12b.o(.x2)
  38. script_test_12b.o(.x3)
  39. The linker scripts set the absolute symbol INTERLEAVED, which we
  40. test here to determine which ordering to expect. The scripts also
  41. define the symbols test_array_start and test_array_end.
  42. */
  43. extern int test_array_start;
  44. extern int test_array_end;
  45. extern char interleaved __attribute__((__aligned__(1)));
  46. int
  47. main(void)
  48. {
  49. int last = 0;
  50. int *p;
  51. long should_be_interleaved = (long)&interleaved;
  52. int mask = (should_be_interleaved == 1 ? 0x7f : 0xff);
  53. for (p = &test_array_start; p < &test_array_end; ++p)
  54. {
  55. int next = *p & mask;
  56. if (next <= last)
  57. return 1;
  58. last = next;
  59. }
  60. return 0;
  61. }
  62. int a1[] __attribute((section(".x1"))) = { 0x01, 0x02, 0x03, 0x04 };
  63. int a2[] __attribute((section(".x2"))) = { 0x11, 0x12, 0x13, 0x14};
  64. int a3[] __attribute((section(".x3"))) = { 0x21, 0x22, 0x23, 0x24 };
  65. int a4[] __attribute((section(".x4"))) = { 0xff, 0xff, 0xff, 0xff };