]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: compiler: add macros to declare section names
authorWilly Tarreau <w@1wt.eu>
Sat, 10 Apr 2021 13:53:45 +0000 (15:53 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 10 Apr 2021 17:27:41 +0000 (19:27 +0200)
HA_SECTION() is used as an attribute to force a section name. This is
required because OSX prepends "__DATA, " in front of the declaration.
HA_SECTION_START() and HA_SECTION_STOP() are used as post-attribute on
variable declaration to designate the section start/end (needed only on
OSX, empty on others).

For platforms with an obsolete linker, all macros are left empty. It would
possibly still work on some of them but this will not be needed anyway.

include/haproxy/compiler.h

index 87012d27c25f728c29ce3a9aea306eb7eb5e0547..c18331962fe56caacd8059ed0f48a8587ed64e57 100644 (file)
  */
 #define __maybe_unused __attribute__((unused))
 
+/* These macros are used to declare a section name for a variable.
+ * WARNING: keep section names short, as MacOS limits them to 16 characters.
+ * The _START and _STOP attributes have to be placed after the start and stop
+ * weak symbol declarations, and are only used by MacOS.
+ */
+#if !defined(USE_OBSOLETE_LINKER)
+
+#ifdef __APPLE__
+#define HA_SECTION(s)           __attribute__((__section__("__DATA, " s)))
+#define HA_SECTION_START(s)     __asm("section$start$__DATA$" s)
+#define HA_SECTION_STOP(s)      __asm("section$end$__DATA$" s)
+#else
+#define HA_SECTION(s)           __attribute__((__section__(s)))
+#define HA_SECTION_START(s)
+#define HA_SECTION_STOP(s)
+#endif
+
+#else // obsolete linker below, let's just not force any section
+
+#define HA_SECTION(s)
+#define HA_SECTION_START(s)
+#define HA_SECTION_STOP(s)
+
+#endif // USE_OBSOLETE_LINKER
+
 /* This allows gcc to know that some locations are never reached, for example
  * after a longjmp() in the Lua code, hence that some errors caught by such
  * methods cannot propagate further. This is important with gcc versions 6 and