File indexing completed on 2024-05-18 08:30:10
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 #ifndef PLUGIN_API_H
0027 #define PLUGIN_API_H
0028
0029 #ifdef HAVE_STDINT_H
0030 #include <stdint.h>
0031 #elif defined(HAVE_INTTYPES_H)
0032 #include <inttypes.h>
0033 #endif
0034 #include <sys/types.h>
0035 #if !defined(HAVE_STDINT_H) && !defined(HAVE_INTTYPES_H) && \
0036 !defined(UINT64_MAX) && !defined(uint64_t)
0037 #error cannot find uint64_t type
0038 #endif
0039
0040
0041 #if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
0042 defined(__ORDER_LITTLE_ENDIAN__) && defined(__ORDER_PDP_ENDIAN__)
0043 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
0044 #define PLUGIN_LITTLE_ENDIAN 1
0045 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
0046 #define PLUGIN_BIG_ENDIAN 1
0047 #elif __BYTE_ORDER__ == __ORDER_PDP_ENDIAN__
0048 #define PLUGIN_PDP_ENDIAN 1
0049 #endif
0050 #else
0051
0052 #if defined(__GLIBC__) || defined(__GNU_LIBRARY__) || defined(__ANDROID__)
0053 #include <endian.h>
0054 #ifdef __BYTE_ORDER
0055 #if __BYTE_ORDER == __LITTLE_ENDIAN
0056 #define PLUGIN_LITTLE_ENDIAN 1
0057 #elif __BYTE_ORDER == __BIG_ENDIAN
0058 #define PLUGIN_BIG_ENDIAN 1
0059 #endif
0060 #endif
0061 #endif
0062
0063 #if defined(__SVR4) && defined(__sun)
0064 #include <sys/byteorder.h>
0065 #endif
0066 #if defined(__FreeBSD__) || defined(__NetBSD__) || \
0067 defined(__DragonFly__) || defined(__minix)
0068 #include <sys/endian.h>
0069 #endif
0070 #if defined(__OpenBSD__)
0071 #include <machine/endian.h>
0072 #endif
0073
0074 #ifdef _BYTE_ORDER
0075 #if _BYTE_ORDER == _LITTLE_ENDIAN
0076 #define PLUGIN_LITTLE_ENDIAN 1
0077 #elif _BYTE_ORDER == _BIG_ENDIAN
0078 #define PLUGIN_BIG_ENDIAN 1
0079 #endif
0080 #endif
0081
0082 #if defined(_WIN32)
0083 #define PLUGIN_LITTLE_ENDIAN 1
0084 #endif
0085
0086 #ifdef __LITTLE_ENDIAN__
0087 #define PLUGIN_LITTLE_ENDIAN 1
0088 #endif
0089 #ifdef __BIG_ENDIAN__
0090 #define PLUGIN_BIG_ENDIAN 1
0091 #endif
0092 #endif
0093
0094 #ifdef __cplusplus
0095 extern "C"
0096 {
0097 #endif
0098
0099
0100
0101 enum ld_plugin_status
0102 {
0103 LDPS_OK = 0,
0104 LDPS_NO_SYMS,
0105 LDPS_BAD_HANDLE,
0106 LDPS_ERR
0107
0108 };
0109
0110
0111
0112 enum ld_plugin_api_version
0113 {
0114 LD_PLUGIN_API_VERSION = 1
0115 };
0116
0117
0118
0119 enum ld_plugin_output_file_type
0120 {
0121 LDPO_REL,
0122 LDPO_EXEC,
0123 LDPO_DYN,
0124 LDPO_PIE
0125 };
0126
0127
0128
0129 struct ld_plugin_input_file
0130 {
0131 const char *name;
0132 int fd;
0133 off_t offset;
0134 off_t filesize;
0135 void *handle;
0136 };
0137
0138
0139
0140 struct ld_plugin_symbol
0141 {
0142 char *name;
0143 char *version;
0144
0145
0146 #if PLUGIN_BIG_ENDIAN == 1
0147 char unused;
0148 char section_kind;
0149 char symbol_type;
0150 char def;
0151 #elif PLUGIN_LITTLE_ENDIAN == 1
0152 char def;
0153 char symbol_type;
0154 char section_kind;
0155 char unused;
0156 #elif PLUGIN_PDP_ENDIAN == 1
0157 char symbol_type;
0158 char def;
0159 char unused;
0160 char section_kind;
0161 #else
0162 #error "Could not detect architecture endianess"
0163 #endif
0164 int visibility;
0165 uint64_t size;
0166 char *comdat_key;
0167 int resolution;
0168 };
0169
0170
0171
0172 struct ld_plugin_section
0173 {
0174 const void* handle;
0175 unsigned int shndx;
0176 };
0177
0178
0179
0180 enum ld_plugin_symbol_kind
0181 {
0182 LDPK_DEF,
0183 LDPK_WEAKDEF,
0184 LDPK_UNDEF,
0185 LDPK_WEAKUNDEF,
0186 LDPK_COMMON
0187 };
0188
0189
0190
0191 enum ld_plugin_symbol_visibility
0192 {
0193 LDPV_DEFAULT,
0194 LDPV_PROTECTED,
0195 LDPV_INTERNAL,
0196 LDPV_HIDDEN
0197 };
0198
0199
0200
0201 enum ld_plugin_symbol_type
0202 {
0203 LDST_UNKNOWN,
0204 LDST_FUNCTION,
0205 LDST_VARIABLE
0206 };
0207
0208 enum ld_plugin_symbol_section_kind
0209 {
0210 LDSSK_DEFAULT,
0211 LDSSK_BSS
0212 };
0213
0214
0215
0216 enum ld_plugin_symbol_resolution
0217 {
0218 LDPR_UNKNOWN = 0,
0219
0220
0221 LDPR_UNDEF,
0222
0223
0224
0225 LDPR_PREVAILING_DEF,
0226
0227
0228
0229
0230 LDPR_PREVAILING_DEF_IRONLY,
0231
0232
0233
0234 LDPR_PREEMPTED_REG,
0235
0236
0237 LDPR_PREEMPTED_IR,
0238
0239
0240 LDPR_RESOLVED_IR,
0241
0242
0243
0244 LDPR_RESOLVED_EXEC,
0245
0246
0247 LDPR_RESOLVED_DYN,
0248
0249
0250
0251
0252
0253 LDPR_PREVAILING_DEF_IRONLY_EXP
0254 };
0255
0256
0257
0258 typedef
0259 enum ld_plugin_status
0260 (*ld_plugin_claim_file_handler) (
0261 const struct ld_plugin_input_file *file, int *claimed);
0262
0263
0264
0265 typedef
0266 enum ld_plugin_status
0267 (*ld_plugin_all_symbols_read_handler) (void);
0268
0269
0270
0271 typedef
0272 enum ld_plugin_status
0273 (*ld_plugin_cleanup_handler) (void);
0274
0275
0276
0277 typedef
0278 enum ld_plugin_status
0279 (*ld_plugin_register_claim_file) (ld_plugin_claim_file_handler handler);
0280
0281
0282
0283 typedef
0284 enum ld_plugin_status
0285 (*ld_plugin_register_all_symbols_read) (
0286 ld_plugin_all_symbols_read_handler handler);
0287
0288
0289
0290 typedef
0291 enum ld_plugin_status
0292 (*ld_plugin_register_cleanup) (ld_plugin_cleanup_handler handler);
0293
0294
0295
0296 typedef
0297 enum ld_plugin_status
0298 (*ld_plugin_add_symbols) (void *handle, int nsyms,
0299 const struct ld_plugin_symbol *syms);
0300
0301
0302
0303
0304 typedef
0305 enum ld_plugin_status
0306 (*ld_plugin_get_input_file) (const void *handle,
0307 struct ld_plugin_input_file *file);
0308
0309 typedef
0310 enum ld_plugin_status
0311 (*ld_plugin_get_view) (const void *handle, const void **viewp);
0312
0313
0314
0315 typedef
0316 enum ld_plugin_status
0317 (*ld_plugin_release_input_file) (const void *handle);
0318
0319
0320
0321 typedef
0322 enum ld_plugin_status
0323 (*ld_plugin_get_symbols) (const void *handle, int nsyms,
0324 struct ld_plugin_symbol *syms);
0325
0326
0327
0328 typedef
0329 enum ld_plugin_status
0330 (*ld_plugin_add_input_file) (const char *pathname);
0331
0332
0333
0334 typedef
0335 enum ld_plugin_status
0336 (*ld_plugin_add_input_library) (const char *libname);
0337
0338
0339
0340 typedef
0341 enum ld_plugin_status
0342 (*ld_plugin_set_extra_library_path) (const char *path);
0343
0344
0345
0346 typedef
0347 enum ld_plugin_status
0348 (*ld_plugin_message) (int level, const char *format, ...);
0349
0350
0351
0352
0353
0354
0355 typedef
0356 enum ld_plugin_status
0357 (*ld_plugin_get_input_section_count) (const void* handle, unsigned int *count);
0358
0359
0360
0361
0362
0363 typedef
0364 enum ld_plugin_status
0365 (*ld_plugin_get_input_section_type) (const struct ld_plugin_section section,
0366 unsigned int *type);
0367
0368
0369
0370
0371
0372
0373 typedef
0374 enum ld_plugin_status
0375 (*ld_plugin_get_input_section_name) (const struct ld_plugin_section section,
0376 char **section_name_ptr);
0377
0378
0379
0380
0381
0382
0383
0384 typedef
0385 enum ld_plugin_status
0386 (*ld_plugin_get_input_section_contents) (const struct ld_plugin_section section,
0387 const unsigned char **section_contents,
0388 size_t* len);
0389
0390
0391
0392
0393
0394
0395
0396 typedef
0397 enum ld_plugin_status
0398 (*ld_plugin_update_section_order) (const struct ld_plugin_section *section_list,
0399 unsigned int num_sections);
0400
0401
0402
0403
0404
0405 typedef
0406 enum ld_plugin_status
0407 (*ld_plugin_allow_section_ordering) (void);
0408
0409
0410
0411
0412
0413
0414 typedef
0415 enum ld_plugin_status
0416 (*ld_plugin_allow_unique_segment_for_sections) (void);
0417
0418
0419
0420
0421
0422
0423
0424
0425
0426
0427 typedef
0428 enum ld_plugin_status
0429 (*ld_plugin_unique_segment_for_sections) (
0430 const char* segment_name,
0431 uint64_t segment_flags,
0432 uint64_t segment_alignment,
0433 const struct ld_plugin_section * section_list,
0434 unsigned int num_sections);
0435
0436
0437
0438
0439
0440
0441 typedef
0442 enum ld_plugin_status
0443 (*ld_plugin_get_input_section_alignment) (const struct ld_plugin_section section,
0444 unsigned int *addralign);
0445
0446
0447
0448
0449
0450
0451 typedef
0452 enum ld_plugin_status
0453 (*ld_plugin_get_input_section_size) (const struct ld_plugin_section section,
0454 uint64_t *secsize);
0455
0456 typedef
0457 enum ld_plugin_status
0458 (*ld_plugin_new_input_handler) (const struct ld_plugin_input_file *file);
0459
0460
0461
0462
0463
0464
0465 typedef
0466 enum ld_plugin_status
0467 (*ld_plugin_register_new_input) (ld_plugin_new_input_handler handler);
0468
0469
0470
0471
0472
0473 typedef
0474 enum ld_plugin_status
0475 (*ld_plugin_get_wrap_symbols) (uint64_t *num_symbols,
0476 const char ***wrap_symbol_list);
0477
0478 enum ld_plugin_level
0479 {
0480 LDPL_INFO,
0481 LDPL_WARNING,
0482 LDPL_ERROR,
0483 LDPL_FATAL
0484 };
0485
0486
0487
0488 enum ld_plugin_tag
0489 {
0490 LDPT_NULL = 0,
0491 LDPT_API_VERSION = 1,
0492 LDPT_GOLD_VERSION = 2,
0493 LDPT_LINKER_OUTPUT = 3,
0494 LDPT_OPTION = 4,
0495 LDPT_REGISTER_CLAIM_FILE_HOOK = 5,
0496 LDPT_REGISTER_ALL_SYMBOLS_READ_HOOK = 6,
0497 LDPT_REGISTER_CLEANUP_HOOK = 7,
0498 LDPT_ADD_SYMBOLS = 8,
0499 LDPT_GET_SYMBOLS = 9,
0500 LDPT_ADD_INPUT_FILE = 10,
0501 LDPT_MESSAGE = 11,
0502 LDPT_GET_INPUT_FILE = 12,
0503 LDPT_RELEASE_INPUT_FILE = 13,
0504 LDPT_ADD_INPUT_LIBRARY = 14,
0505 LDPT_OUTPUT_NAME = 15,
0506 LDPT_SET_EXTRA_LIBRARY_PATH = 16,
0507 LDPT_GNU_LD_VERSION = 17,
0508 LDPT_GET_VIEW = 18,
0509 LDPT_GET_INPUT_SECTION_COUNT = 19,
0510 LDPT_GET_INPUT_SECTION_TYPE = 20,
0511 LDPT_GET_INPUT_SECTION_NAME = 21,
0512 LDPT_GET_INPUT_SECTION_CONTENTS = 22,
0513 LDPT_UPDATE_SECTION_ORDER = 23,
0514 LDPT_ALLOW_SECTION_ORDERING = 24,
0515 LDPT_GET_SYMBOLS_V2 = 25,
0516 LDPT_ALLOW_UNIQUE_SEGMENT_FOR_SECTIONS = 26,
0517 LDPT_UNIQUE_SEGMENT_FOR_SECTIONS = 27,
0518 LDPT_GET_SYMBOLS_V3 = 28,
0519 LDPT_GET_INPUT_SECTION_ALIGNMENT = 29,
0520 LDPT_GET_INPUT_SECTION_SIZE = 30,
0521 LDPT_REGISTER_NEW_INPUT_HOOK = 31,
0522 LDPT_GET_WRAP_SYMBOLS = 32,
0523 LDPT_ADD_SYMBOLS_V2 = 33
0524 };
0525
0526
0527
0528 struct ld_plugin_tv
0529 {
0530 enum ld_plugin_tag tv_tag;
0531 union
0532 {
0533 int tv_val;
0534 const char *tv_string;
0535 ld_plugin_register_claim_file tv_register_claim_file;
0536 ld_plugin_register_all_symbols_read tv_register_all_symbols_read;
0537 ld_plugin_register_cleanup tv_register_cleanup;
0538 ld_plugin_add_symbols tv_add_symbols;
0539 ld_plugin_get_symbols tv_get_symbols;
0540 ld_plugin_add_input_file tv_add_input_file;
0541 ld_plugin_message tv_message;
0542 ld_plugin_get_input_file tv_get_input_file;
0543 ld_plugin_get_view tv_get_view;
0544 ld_plugin_release_input_file tv_release_input_file;
0545 ld_plugin_add_input_library tv_add_input_library;
0546 ld_plugin_set_extra_library_path tv_set_extra_library_path;
0547 ld_plugin_get_input_section_count tv_get_input_section_count;
0548 ld_plugin_get_input_section_type tv_get_input_section_type;
0549 ld_plugin_get_input_section_name tv_get_input_section_name;
0550 ld_plugin_get_input_section_contents tv_get_input_section_contents;
0551 ld_plugin_update_section_order tv_update_section_order;
0552 ld_plugin_allow_section_ordering tv_allow_section_ordering;
0553 ld_plugin_allow_unique_segment_for_sections tv_allow_unique_segment_for_sections;
0554 ld_plugin_unique_segment_for_sections tv_unique_segment_for_sections;
0555 ld_plugin_get_input_section_alignment tv_get_input_section_alignment;
0556 ld_plugin_get_input_section_size tv_get_input_section_size;
0557 ld_plugin_register_new_input tv_register_new_input;
0558 ld_plugin_get_wrap_symbols tv_get_wrap_symbols;
0559 } tv_u;
0560 };
0561
0562
0563
0564 typedef
0565 enum ld_plugin_status
0566 (*ld_plugin_onload) (struct ld_plugin_tv *tv);
0567
0568 #ifdef __cplusplus
0569 }
0570 #endif
0571
0572 #endif