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