diff options
| author | Tharo <tharo10600@gmail.com> | 2026-05-06 22:33:03 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-05-06 23:33:03 +0200 |
| commit | 2c481eaeebcfe2d78efa305d3e1b908100bebf14 (patch) | |
| tree | f06c98329359fc04189040eeb3e056c150dd47ee /tools/com-plugin/plugin.c | |
| parent | 70701b8ac9b5f41a2cc71a8ce59a211c137aa298 (diff) | |
Partial linking of spec segments (#2661)
* Partial linking of overlay segments, relax linker script alignment
* Partial linking of all spec segments
* Fix update, remove _RomPos from linker script
* iQue version working pending COM-plugin update
* Add plf map file resolution to sym_info.py, local symbol merging is broken
* git subrepo pull tools/com-plugin
subrepo:
subdir: "tools/com-plugin"
merged: "c4f3ba845"
upstream:
origin: "git@github.com:Thar0/com-plugin.git"
branch: "main"
commit: "c4f3ba845"
git-subrepo:
version: "0.4.6"
origin: "https://github.com/ingydotnet/git-subrepo"
commit: "110b9eb"
* Make tools compatible with partial linking
Co-authored-by: Anghelo Carvajal <angheloalf95@gmail.com>
* Remove unused files
* Fix some makefile bits
* mkspecrules cleanup
* Comment on the makerom linker layout in mkldscript
* Revert linker padding strategy back to pad_text spec directives
* Comment on objcopy elf -> rom step
* Adjust tool descriptions
* Fix compressed builds
* rm reloc_prereq, no longer used
* Makefile merge fix
Co-authored-by: Dragorn421 <Dragorn421@users.noreply.github.com>
---------
Co-authored-by: Anghelo Carvajal <angheloalf95@gmail.com>
Co-authored-by: Dragorn421 <Dragorn421@users.noreply.github.com>
Diffstat (limited to 'tools/com-plugin/plugin.c')
| -rw-r--r-- | tools/com-plugin/plugin.c | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/tools/com-plugin/plugin.c b/tools/com-plugin/plugin.c index cd1fa0a53..91db2aa17 100644 --- a/tools/com-plugin/plugin.c +++ b/tools/com-plugin/plugin.c @@ -70,12 +70,13 @@ static struct { size_t num_ofiles; // Our options char *order_path; + size_t min_align; // LD plugin int api_version; int gnu_ld_version; int linker_output; const char *output_name; - ld_plugin_message message; + ld_plugin_message message __attribute__((format(printf, 2, 3))); ld_plugin_add_symbols add_symbols; ld_plugin_get_symbols get_symbols; ld_plugin_get_symbols get_symbols_v2; @@ -339,6 +340,8 @@ all_symbols_read(void) sym_offset += be32toh(sym->st_size); } + if (greatest_align < pl.min_align) + greatest_align = pl.min_align; sym_offset = (sym_offset + greatest_align - 1) & ~(greatest_align - 1); size_t symtab_size = ftell(elf) - symtab_offset; @@ -491,7 +494,7 @@ parse_order_file(const char *order_file) // Read the entire bss order file and null-terminate it FILE *bss_order = fopen(order_file, "rb"); if (bss_order == NULL) { - pl.message(LDPL_FATAL, "Could not open bss order file %s for reading: %s", bss_order, strerror(errno)); + pl.message(LDPL_FATAL, "Could not open bss order file \"%s\" for reading: %s", order_file, strerror(errno)); return LDPS_ERR; } @@ -501,7 +504,7 @@ parse_order_file(const char *order_file) pl.string_pool = malloc((fsize + 1) * sizeof(char)); if (fread(pl.string_pool, fsize, 1, bss_order) != 1) { - pl.message(LDPL_FATAL, "Failed to read bss order file %s: %s", order_file, strerror(errno)); + pl.message(LDPL_FATAL, "Failed to read bss order file \"%s\": %s", order_file, strerror(errno)); free(pl.string_pool); fclose(bss_order); return LDPS_ERR; @@ -716,12 +719,55 @@ syntaxerror: } static enum ld_plugin_status +read_int(size_t *out, const char *s) +{ + if (s[0] == '\0') + goto err; + + size_t res; + + size_t length = strlen(s); + size_t start = 0; + + // we expect unsigned input, error on - and skip + + if (s[start] == '-') + goto err; + if (s[start] == '+') + start++; + + // determine the base of the input via the presence of an 0x prefix + int base; + if (start + 2 < length && s[start + 0] == '0' && tolower(s[start + 1]) == 'x') { + start += 2; + base = 16; + } else { + base = 10; + } + + // read the value in the appropriate base + char *str_end; + res = strtoull(&s[start], &str_end, base); + size_t end = str_end - s; + if (start == end) + goto err; + + *out = res; + return LDPS_OK; +err: + fprintf(stderr, "Bad input to min_align, must be an unsigned integer in base 10 or 16: %s", s); + return LDPS_ERR; +} + +static enum ld_plugin_status parse_option(const char *opt) { if (strequ(opt, "order=")) { pl.order_path = strdup(opt + sizeof("order=") - 1); return LDPS_OK; } + if (strequ(opt, "min_align=")) { + return read_int(&pl.min_align, opt + sizeof("min_align=") - 1); + } fprintf(stderr, "Unknown option: %s\n", opt); return LDPS_ERR; |
