]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: Revert usage of asm-code in MTYPE definitions
authorJuergen Werner <juergen@opensourcerouting.org>
Tue, 1 Oct 2019 12:24:20 +0000 (14:24 +0200)
committerJuergen Werner <juergen@opensourcerouting.org>
Tue, 1 Oct 2019 13:23:00 +0000 (15:23 +0200)
The asm-code was interpreted inconsistently for different platforms.
In particular for AArch64 this caused UB, if multiple static MTYPEs
where defined in one file. All static MTYPE_* could point to the same
memory location (namely the first defined MTYPE) OR to their respective
(correct) locations depending on the context of their usage.

Signed-off-by: Juergen Werner <juergen@opensourcerouting.org>
doc/developer/memtypes.rst
lib/memory.h

index 13f6b43bbfd6510b8a5615186346a46ecf0eaaf7..1af871963a8e75a4f67b7e340565872ce12b0b39 100644 (file)
@@ -48,7 +48,7 @@ Definition
    should be used to create these, but in some cases it is useful to pass a
    ``struct memtype *`` pointer to some helper function.
 
-   The ``MTYPE_name`` created by the macros is declared as an array, i.e.
+   The ``MTYPE_name`` created by the macros is declared as a pointer, i.e.
    a function taking a ``struct memtype *`` argument can be called with an
    ``MTYPE_name`` argument (as opposed to ``&MTYPE_name``.)
 
index 14cd76f2f50937dcd8d1e84d080b1dc1946bf974..8de5c4c2bf0b5627d36d55230c766b613c187271 100644 (file)
@@ -101,14 +101,9 @@ struct memgroup {
                *_mg_##mname.ref = _mg_##mname.next;                           \
        }
 
-
-/* the array is a trick to make the "MTYPE_FOO" name work as a pointer without
- * putting a & in front of it, so we can do "XMALLOC(MTYPE_FOO, ...)" instead
- * of "XMALLOC(&MTYPE_FOO, ...)".
- */
 #define DECLARE_MTYPE(name)                                                    \
        extern struct memtype _mt_##name;                                      \
-       extern struct memtype MTYPE_##name[1];                                 \
+       extern struct memtype *const MTYPE_##name;                             \
        /* end */
 
 #define DEFINE_MTYPE_ATTR(group, mname, attr, desc)                            \
@@ -138,17 +133,14 @@ struct memgroup {
        }                                                                      \
        /* end */
 
-/* can't quite get gcc to emit the alias correctly, so asm-alias it is :/ */
 #define DEFINE_MTYPE(group, name, desc)                                        \
        DEFINE_MTYPE_ATTR(group, name, , desc)                                 \
-       __asm__(".equiv MTYPE_" #name ", _mt_" #name "\n\t"                    \
-               ".global MTYPE_" #name "\n");                                  \
+       struct memtype *const MTYPE_##name = &_mt_##name;                      \
        /* end */
-/* and this one's borked on clang, it drops static on aliases :/, so... asm */
+
 #define DEFINE_MTYPE_STATIC(group, name, desc)                                 \
        DEFINE_MTYPE_ATTR(group, name, static, desc)                           \
-       extern struct memtype MTYPE_##name[1];                                 \
-       __asm__(".equiv MTYPE_" #name ", _mt_" #name "\n");                    \
+       static struct memtype *const MTYPE_##name = &_mt_##name;               \
        /* end */
 
 DECLARE_MGROUP(LIB)