You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

71 lines
3.2 KiB

  1. From 4d8ebeddc56f49aa0b4d7cec506cab14320e1bb4 Mon Sep 17 00:00:00 2001
  2. From: Juergen Werner <juergen@opensourcerouting.org>
  3. Date: Tue, 1 Oct 2019 14:24:20 +0200
  4. Subject: [PATCH] lib: Revert usage of asm-code in MTYPE definitions
  5. The asm-code was interpreted inconsistently for different platforms.
  6. In particular for AArch64 this caused UB, if multiple static MTYPEs
  7. where defined in one file. All static MTYPE_* could point to the same
  8. memory location (namely the first defined MTYPE) OR to their respective
  9. (correct) locations depending on the context of their usage.
  10. Signed-off-by: Juergen Werner <juergen@opensourcerouting.org>
  11. ---
  12. doc/developer/memtypes.rst | 2 +-
  13. lib/memory.h | 16 ++++------------
  14. 2 files changed, 5 insertions(+), 13 deletions(-)
  15. diff --git a/doc/developer/memtypes.rst b/doc/developer/memtypes.rst
  16. index 13f6b43bbf..1af871963a 100644
  17. --- a/doc/developer/memtypes.rst
  18. +++ b/doc/developer/memtypes.rst
  19. @@ -48,7 +48,7 @@ Definition
  20. should be used to create these, but in some cases it is useful to pass a
  21. ``struct memtype *`` pointer to some helper function.
  22. - The ``MTYPE_name`` created by the macros is declared as an array, i.e.
  23. + The ``MTYPE_name`` created by the macros is declared as a pointer, i.e.
  24. a function taking a ``struct memtype *`` argument can be called with an
  25. ``MTYPE_name`` argument (as opposed to ``&MTYPE_name``.)
  26. diff --git a/lib/memory.h b/lib/memory.h
  27. index 14cd76f2f5..8de5c4c2bf 100644
  28. --- a/lib/memory.h
  29. +++ b/lib/memory.h
  30. @@ -101,14 +101,9 @@ struct memgroup {
  31. *_mg_##mname.ref = _mg_##mname.next; \
  32. }
  33. -
  34. -/* the array is a trick to make the "MTYPE_FOO" name work as a pointer without
  35. - * putting a & in front of it, so we can do "XMALLOC(MTYPE_FOO, ...)" instead
  36. - * of "XMALLOC(&MTYPE_FOO, ...)".
  37. - */
  38. #define DECLARE_MTYPE(name) \
  39. extern struct memtype _mt_##name; \
  40. - extern struct memtype MTYPE_##name[1]; \
  41. + extern struct memtype *const MTYPE_##name; \
  42. /* end */
  43. #define DEFINE_MTYPE_ATTR(group, mname, attr, desc) \
  44. @@ -138,17 +133,14 @@ struct memgroup {
  45. } \
  46. /* end */
  47. -/* can't quite get gcc to emit the alias correctly, so asm-alias it is :/ */
  48. #define DEFINE_MTYPE(group, name, desc) \
  49. DEFINE_MTYPE_ATTR(group, name, , desc) \
  50. - __asm__(".equiv MTYPE_" #name ", _mt_" #name "\n\t" \
  51. - ".global MTYPE_" #name "\n"); \
  52. + struct memtype *const MTYPE_##name = &_mt_##name; \
  53. /* end */
  54. -/* and this one's borked on clang, it drops static on aliases :/, so... asm */
  55. +
  56. #define DEFINE_MTYPE_STATIC(group, name, desc) \
  57. DEFINE_MTYPE_ATTR(group, name, static, desc) \
  58. - extern struct memtype MTYPE_##name[1]; \
  59. - __asm__(".equiv MTYPE_" #name ", _mt_" #name "\n"); \
  60. + static struct memtype *const MTYPE_##name = &_mt_##name; \
  61. /* end */
  62. DECLARE_MGROUP(LIB)