diff options
author | Toomas Soome <tsoome@me.com> | 2022-10-07 15:06:57 +0300 |
---|---|---|
committer | Toomas Soome <tsoome@me.com> | 2022-11-07 18:53:06 +0200 |
commit | d56b5f9f1e06794379c22afb6e6ba0ac704e4214 (patch) | |
tree | b420e0ed7f9001a58c866bb5318322ba324a7d97 | |
parent | f8e30ca2ec5c9a7f5bd81df127b915fdc6bb0c1a (diff) | |
download | illumos-joyent-d56b5f9f1e06794379c22afb6e6ba0ac704e4214.tar.gz |
15067 linker set should be declared WEAK
Reviewed by: Jason King <jason.brian.king+illumos@gmail.com>
Reviewed by: Patrick Mooney <pmooney@pfmooney.com>
Approved by: Gordon Ross <gordon.w.ross@gmail.com>
-rw-r--r-- | usr/src/boot/sys/sys/cdefs.h | 4 | ||||
-rw-r--r-- | usr/src/boot/sys/sys/linker_set.h | 4 | ||||
-rw-r--r-- | usr/src/test/elf-tests/tests/linker-sets/simple-src.c | 44 | ||||
-rw-r--r-- | usr/src/uts/common/sys/linker_set.h | 11 |
4 files changed, 16 insertions, 47 deletions
diff --git a/usr/src/boot/sys/sys/cdefs.h b/usr/src/boot/sys/sys/cdefs.h index 29b06e6946..ff202cbd9b 100644 --- a/usr/src/boot/sys/sys/cdefs.h +++ b/usr/src/boot/sys/sys/cdefs.h @@ -587,8 +587,8 @@ #endif /* __STDC__ */ #endif /* __GNUC__ || __INTEL_COMPILER */ -#define __GLOBL1(sym) __asm__(".globl " #sym) -#define __GLOBL(sym) __GLOBL1(sym) +#define __GLOBL(sym) __asm__(".globl " __XSTRING(sym)) +#define __WEAK(sym) __asm__(".weak " __XSTRING(sym)) #if defined(__GNUC__) || defined(__INTEL_COMPILER) #define __IDSTRING(name,string) __asm__(".ident\t\"" string "\"") diff --git a/usr/src/boot/sys/sys/linker_set.h b/usr/src/boot/sys/sys/linker_set.h index eaffcd1436..8bf2f65999 100644 --- a/usr/src/boot/sys/sys/linker_set.h +++ b/usr/src/boot/sys/sys/linker_set.h @@ -55,8 +55,8 @@ */ #ifdef __GNUCLIKE___SECTION #define __MAKE_SET(set, sym) \ - __GLOBL(__CONCAT(__start_set_,set)); \ - __GLOBL(__CONCAT(__stop_set_,set)); \ + __WEAK(__CONCAT(__start_set_,set)); \ + __WEAK(__CONCAT(__stop_set_,set)); \ static void const * __MAKE_SET_CONST \ __set_##set##_sym_##sym __section("set_" #set) \ __used = &(sym) diff --git a/usr/src/test/elf-tests/tests/linker-sets/simple-src.c b/usr/src/test/elf-tests/tests/linker-sets/simple-src.c index 388b03da6e..21628442ae 100644 --- a/usr/src/test/elf-tests/tests/linker-sets/simple-src.c +++ b/usr/src/test/elf-tests/tests/linker-sets/simple-src.c @@ -31,41 +31,7 @@ */ #include <stdio.h> - -#define MAKE_SET(set, sym) \ - __asm__(".globl __start_set_" #set); \ - __asm__(".globl __stop_set_" #set); \ - static __attribute__((section("set_" #set), used)) \ - void const *__set_##set##_sym_##sym = &(sym) - -/* - * Initialize before referring to a given linker set. - */ -#define SET_DECLARE(set, ptype) \ - extern __attribute__((weak)) ptype *__start_set_ ## set; \ - extern __attribute__((weak)) ptype *__stop_set_ ## set - -#define SET_BEGIN(set) (&__start_set_ ## set) -#define SET_LIMIT(set) (&__stop_set_ ## set) - -/* - * Iterate over all the elements of a set. - * - * Sets always contain addresses of things, and "pvar" points to words - * containing those addresses. Thus is must be declared as "type **pvar", - * and the address of each set item is obtained inside the loop by "*pvar". - */ -#define SET_FOREACH(pvar, set) \ - for (pvar = SET_BEGIN(set); pvar < SET_LIMIT(set); pvar++) - -#define SET_ITEM(set, i) \ - ((SET_BEGIN(set))[i]) - -/* - * Provide a count of the items in a set. - */ -#define SET_COUNT(set) \ - (SET_LIMIT(set) - SET_BEGIN(set)) +#include <sys/linker_set.h> struct foo { char buf[128]; @@ -77,9 +43,9 @@ struct foo a = { "foo" }; struct foo b = { "bar" }; struct foo c = { "baz" }; -MAKE_SET(foo, a); -MAKE_SET(foo, b); -MAKE_SET(foo, c); +SET_ENTRY(foo, a); +SET_ENTRY(foo, b); +SET_ENTRY(foo, c); int main(int __attribute__((unused)) argc, char __attribute__((unused)) **argv) @@ -87,7 +53,7 @@ main(int __attribute__((unused)) argc, char __attribute__((unused)) **argv) struct foo **c; int i = 0; - printf("Set count: %d\n", SET_COUNT(foo)); + printf("Set count: %d\n", (int)SET_COUNT(foo)); printf("a: %s\n", ((struct foo *)__set_foo_sym_a)->buf); diff --git a/usr/src/uts/common/sys/linker_set.h b/usr/src/uts/common/sys/linker_set.h index 44934bcd97..872e560c2d 100644 --- a/usr/src/uts/common/sys/linker_set.h +++ b/usr/src/uts/common/sys/linker_set.h @@ -41,14 +41,17 @@ #define __CONCAT1(x, y) x ## y #define __CONCAT(x, y) __CONCAT1(x, y) -#define __GLOBL1(sym) __asm__(".globl " #sym) -#define __GLOBL(sym) __GLOBL1(sym) +#define __STRING(x) #x /* stringify without expanding x */ +#define __XSTRING(x) __STRING(x) /* expand x, then stringify */ + +#define __GLOBL(sym) __asm__(".globl " __XSTRING(sym)) +#define __WEAK(sym) __asm__(".weak " __XSTRING(sym)) /* * Private macros, not to be used outside this header file. */ #define __MAKE_SET(set, sym) \ - __GLOBL(__CONCAT(__start_set_, set)); \ - __GLOBL(__CONCAT(__stop_set_, set)); \ + __WEAK(__CONCAT(__start_set_, set)); \ + __WEAK(__CONCAT(__stop_set_, set)); \ static void const * __MAKE_SET_CONST \ __set_##set##_sym_##sym __section("set_" #set) \ __used = &(sym) |