Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- /* <sys/linker_set.h> */
- #include <mach-o/getsect.h>
- #define __LS_VA_STRINGIFY(_x...) #_x
- #define __LS_VA_STRCONCAT(_x,_y) __LS_VA_STRINGIFY(_x,_y)
- #define __LINKER_MAKE_SET(_set, _sym) \
- /*__unused*/ /*static*/ void const * /*const*/ __set_##_set##_sym_##_sym \
- __attribute__ ((section(__LS_VA_STRCONCAT(__DATA,_set)))) = (void *)&_sym
- /* */
- /* <sys/linker_set.h>: getsectdatafromheader() -> getsectdata() */
- static __inline void **
- __linker_set_object_begin_fixed(const char *_set)
- {
- void *_set_begin;
- unsigned long _size;
- _set_begin = getsectdata("__DATA", _set, &_size);
- return( (void **) _set_begin );
- }
- static __inline void **
- __linker_set_object_limit_fixed(const char *_set)
- {
- void *_set_begin;
- unsigned long _size;
- _set_begin = getsectdata("__DATA", _set, &_size);
- return ((void **) ((uintptr_t) _set_begin + _size));
- }
- /* */
- char section[] = "my";
- int x = 5;
- int y = 10;
- int z = 22;
- __LINKER_MAKE_SET(my,x);
- __LINKER_MAKE_SET(my,y);
- __LINKER_MAKE_SET(my,z);
- void
- main()
- {
- printf("Number of entries in section: %d\n",
- __linker_set_object_limit_fixed(section) - __linker_set_object_begin_fixed(section));
- printf("Data of first entry: %d\n", *((int *) *__linker_set_object_begin_fixed(section)) );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement