Skip to content

Instantly share code, notes, and snippets.

@gabrielschulhof
Created May 11, 2017 07:07
Show Gist options
  • Save gabrielschulhof/02fa140c2c4f93c82ee83e7773bdeb90 to your computer and use it in GitHub Desktop.
Save gabrielschulhof/02fa140c2c4f93c82ee83e7773bdeb90 to your computer and use it in GitHub Desktop.
#include <stdio.h>
typedef struct {
int x;
int y;
} something_t;
static something_t a __attribute((used, section("foo_data"), aligned(sizeof (void *)))) = { .x = 5, .y = 6 };
static something_t b __attribute((used, section("foo_data"), aligned(sizeof (void *)))) = { .x = 7, .y = 8 };
static something_t c __attribute((used, section("bar_data"), aligned(sizeof (void *)))) = { .x = 1, .y = 2 };
static something_t d __attribute((used, section("bar_data"), aligned(sizeof (void *)))) = { .x = 3, .y = 4 };
extern something_t __start_foo_data[] __attribute__((weak));
extern something_t __stop_foo_data[] __attribute__((weak));
extern something_t *__start_bar_data __attribute__((weak));
extern something_t *__stop_bar_data __attribute__((weak));
int
main()
{
printf("__start_foo_data: %p\n", __start_foo_data);
printf("__stop_foo_data: %p\n", __stop_foo_data);
printf("__start_bar_data: %p\n", __start_bar_data);
printf("__stop_bar_data: %p\n", __stop_bar_data);
return 0;
}
$ ./tmp
__start_foo_data: 0x601028
__stop_foo_data: 0x601038
__start_bar_data: 0x200000001
__stop_bar_data: (nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment