6 #define DIE do { fprintf(stderr, "ksplice: died at %s:%d\n", __FILE__, __LINE__); abort(); } while(0)
7 #define assert(x) do { if(!(x)) DIE; } while(0)
8 #define align(x, n) ((((x)+(n)-1)/(n))*(n))
10 #define DECLARE_VEC_TYPE(elt_t, vectype) \
17 /* void vec_init(struct vectype *vec); */
18 #define vec_init(vec) *(vec) = (typeof(*(vec))) { NULL, 0, 0 }
20 /* void vec_move(struct vectype *dstvec, struct vectype *srcvec); */
21 #define vec_move(dstvec, srcvec) do { \
22 typeof(srcvec) _srcvec = (srcvec); \
23 *(dstvec) = *(_srcvec); \
27 /* void vec_free(struct vectype *vec); */
28 #define vec_free(vec) do { \
29 typeof(vec) _vec1 = (vec); \
34 void vec_do_reserve(void **data
, size_t *mem_size
, size_t newsize
);
36 /* void vec_reserve(struct vectype *vec, size_t new_mem_size); */
37 #define vec_reserve(vec, new_mem_size) do { \
38 typeof(vec) _vec2 = (vec); \
39 vec_do_reserve((void **)&_vec2->data, &_vec2->mem_size, \
43 /* void vec_resize(struct vectype *vec, size_t new_size); */
44 #define vec_resize(vec, new_size) do { \
45 typeof(vec) _vec3 = (vec); \
46 _vec3->size = (new_size); \
47 vec_reserve(_vec3, _vec3->size * sizeof(*_vec3->data)); \
50 /* elt_t *vec_grow(struct vectype *vec, size_t n); */
51 #define vec_grow(vec, n) ({ \
52 typeof(vec) _vec4 = (vec); \
54 vec_resize(_vec4, _vec4->size + _n); \
55 _vec4->data + (_vec4->size - _n); \
58 DECLARE_VEC_TYPE(void, void_vec
);
59 DECLARE_VEC_TYPE(arelent
*, arelentp_vec
);
60 DECLARE_VEC_TYPE(asymbol
*, asymbolp_vec
);
62 #ifndef bfd_get_section_size
63 #define bfd_get_section_size(x) ((x)->_cooked_size)
69 struct void_vec contents
;
71 struct arelentp_vec relocs
;
72 struct supersect
*next
;
75 void get_syms(bfd
*abfd
, struct asymbolp_vec
*syms
);
76 struct supersect
*fetch_supersect(bfd
*abfd
, asection
*sect
,
77 struct asymbolp_vec
*syms
);
79 #define starts_with(str, prefix) \
80 (strncmp(str, prefix, strlen(prefix)) == 0)
81 #define ends_with(str, suffix) \
82 (strlen(str) >= strlen(suffix) && \
83 strcmp(&str[strlen(str) - strlen(suffix)], suffix) == 0)
85 int label_offset(const char *sym_name
);
86 const char *only_label(const char *sym_name
);
87 const char *dup_wolabel(const char *sym_name
);