eh_frame_main.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Unlicense OR CC0-1.0
  5. */
  6. #include <stdio.h>
  7. #include <unistd.h>
  8. #include <assert.h>
  9. #include <string.h>
  10. /**
  11. * @brief Symbols defined by the linker.
  12. * Retrieve the addresses of both .eh_frame_hdr and .eh_frame sections.
  13. */
  14. extern char __eh_frame_hdr;
  15. extern char __eh_frame_hdr_end;
  16. extern char __eh_frame;
  17. extern char __eh_frame_end;
  18. /**
  19. * @brief Pointers to both .eh_frame_hdr and .eh_frame sections.
  20. */
  21. #define EH_FRAME_HDR_ADDR ((void*) (&__eh_frame_hdr))
  22. #define EH_FRAME_HDR_END_ADDR ((void*) (&__eh_frame_hdr_end))
  23. #define EH_FRAME_ADDR ((void*) (&__eh_frame))
  24. #define EH_FRAME_END_ADDR ((void*) (&__eh_frame_end))
  25. void app_main(void)
  26. {
  27. /* As soon as this test compiles, it can be considered passed. The linker should
  28. * test that the eh_frame and eh_frame_hdr sections are not empty but let's make
  29. * sure again that they are not empty. */
  30. assert((EH_FRAME_END_ADDR > EH_FRAME_ADDR) && ".eh_frame section must not be empty");
  31. assert((EH_FRAME_HDR_END_ADDR > EH_FRAME_HDR_ADDR) && ".eh_frame_hdr section must not be empty");
  32. /* Use the symbols just to make sure they won't be optimized away */
  33. printf(".eh_frame start: %p, end: %p\n", EH_FRAME_ADDR, EH_FRAME_END_ADDR);
  34. printf(".eh_frame_hdr start: %p, end: %p\n", EH_FRAME_HDR_ADDR, EH_FRAME_HDR_END_ADDR);
  35. }