summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorruki <[email protected]>2025-12-12 00:43:59 +0800
committerruki <[email protected]>2025-12-12 09:00:45 +0800
commitbf35be31ee869cf75a9a32e52069867326e23cda (patch)
treeb09958d96562f47aafd816b20e489e7c11a7b75b /core/src
parent890c032d88364e69baa41050079e9b69b58fa735 (diff)
fix compile errors
Diffstat (limited to 'core/src')
-rw-r--r--core/src/xmake/binutils/ar/readsyms.c62
-rw-r--r--core/src/xmake/binutils/coff/prefix.h4
-rw-r--r--core/src/xmake/binutils/elf/readsyms.c5
-rw-r--r--core/src/xmake/binutils/mslib/extractlib.c27
-rw-r--r--core/src/xmake/binutils/mslib/readsyms.c15
5 files changed, 64 insertions, 49 deletions
diff --git a/core/src/xmake/binutils/ar/readsyms.c b/core/src/xmake/binutils/ar/readsyms.c
index a95d7ed48..f60460efd 100644
--- a/core/src/xmake/binutils/ar/readsyms.c
+++ b/core/src/xmake/binutils/ar/readsyms.c
@@ -45,12 +45,13 @@ static tb_bool_t xm_binutils_ar_get_member_name(tb_stream_ref_t istream, xm_ar_h
tb_assert_and_check_return_val(istream && header && name && name_size > 0 && name_len && bytes_read, tb_false);
*bytes_read = 0;
- // check for extended name format (#N/L or #1/N)
- // In BSD AR format:
- // - #1/N means name is directly after header, N is total length (including name)
- // - #N/L means name length is N, total length is L
- // - #1/N can also mean name is in long name table at offset 1
- // We'll try to read the name directly from stream first
+ /* check for extended name format (#N/L or #1/N)
+ * In BSD AR format:
+ * - #1/N means name is directly after header, N is total length (including name)
+ * - #N/L means name length is N, total length is L
+ * - #1/N can also mean name is in long name table at offset 1
+ * We'll try to read the name directly from stream first
+ */
if (header->name[0] == '#') {
// find the '/' separator
tb_size_t slash_pos = 0;
@@ -71,9 +72,10 @@ static tb_bool_t xm_binutils_ar_get_member_name(tb_stream_ref_t istream, xm_ar_h
return tb_false;
}
- // In BSD AR format, extended name is directly after header
- // The name data starts immediately after the header, no newline
- // Read exactly total_length bytes for the name section
+ /* In BSD AR format, extended name is directly after header
+ * The name data starts immediately after the header, no newline
+ * Read exactly total_length bytes for the name section
+ */
tb_byte_t c;
tb_size_t name_bytes = 0;
tb_hize_t bytes_read_so_far = 0;
@@ -398,8 +400,9 @@ tb_bool_t xm_binutils_ar_read_symbols(tb_stream_ref_t istream, tb_hize_t base_of
// save member header position
tb_hize_t member_header_pos = tb_stream_offset(istream);
- // read AR header
- // AR header is exactly 60 bytes: name[16] + date[12] + uid[6] + gid[6] + mode[8] + size[10] + fmag[2]
+ /* read AR header
+ * AR header is exactly 60 bytes: name[16] + date[12] + uid[6] + gid[6] + mode[8] + size[10] + fmag[2]
+ */
xm_ar_header_t header;
if (!tb_stream_bread(istream, (tb_byte_t*)&header, sizeof(header))) {
// end of file
@@ -424,12 +427,13 @@ tb_bool_t xm_binutils_ar_read_symbols(tb_stream_ref_t istream, tb_hize_t base_of
skip = tb_true;
} else {
if (xm_binutils_ar_is_symbol_table(member_name)) {
- // parse symbol table
- //
- // The symbol table in the archive only contains symbol names and their offsets,
- // but lacks detailed symbol type information (e.g., distinguishing between code and data).
- // However, for object files that cannot be parsed (e.g., LTO bitcode) or unknown formats,
- // parsing the symbol table serves as a robust fallback to ensure symbols are extracted.
+ /* parse symbol table
+ *
+ * The symbol table in the archive only contains symbol names and their offsets,
+ * but lacks detailed symbol type information (e.g., distinguishing between code and data).
+ * However, for object files that cannot be parsed (e.g., LTO bitcode) or unknown formats,
+ * parsing the symbol table serves as a robust fallback to ensure symbols are extracted.
+ */
tb_hize_t current = tb_stream_offset(istream);
if (tb_strcmp(member_name, "/") == 0) {
xm_binutils_ar_parse_sysv_symdef(istream, member_size, lua, map_idx);
@@ -481,15 +485,16 @@ tb_bool_t xm_binutils_ar_read_symbols(tb_stream_ref_t istream, tb_hize_t base_of
}
if (!read_ok) {
- // try get from map
- //
- // If parsing the object file fails (e.g. for LTO bitcode or unsupported formats),
- // we fall back to using the symbols parsed from the archive symbol table.
- // Although the type information is less accurate (defaulting to "T"),
- // it guarantees that symbols are not lost.
- //
- // cast to lua_Integer to avoid warning C4244 on 32-bit MSVC
- // member_header_pos is tb_hize_t (64-bit), but AR offsets are usually 32-bit
+ /* try get from map
+ *
+ * If parsing the object file fails (e.g. for LTO bitcode or unsupported formats),
+ * we fall back to using the symbols parsed from the archive symbol table.
+ * Although the type information is less accurate (defaulting to "T"),
+ * it guarantees that symbols are not lost.
+ *
+ * cast to lua_Integer to avoid warning C4244 on 32-bit MSVC
+ * member_header_pos is tb_hize_t (64-bit), but AR offsets are usually 32-bit
+ */
lua_pushinteger(lua, (lua_Integer)member_header_pos);
lua_rawget(lua, map_idx);
if (!lua_isnil(lua, -1)) {
@@ -518,8 +523,9 @@ tb_bool_t xm_binutils_ar_read_symbols(tb_stream_ref_t istream, tb_hize_t base_of
break;
}
} else if (remaining_size < 0) {
- // should not happen if readsyms functions respect boundaries, but just in case
- // seek back to correct position
+ /* should not happen if readsyms functions respect boundaries, but just in case
+ * seek back to correct position
+ */
if (!tb_stream_seek(istream, current_pos + (tb_hize_t)member_size - name_bytes_read + (member_size % 2))) {
ok = tb_false;
break;
diff --git a/core/src/xmake/binutils/coff/prefix.h b/core/src/xmake/binutils/coff/prefix.h
index 60f6ded96..6b009b056 100644
--- a/core/src/xmake/binutils/coff/prefix.h
+++ b/core/src/xmake/binutils/coff/prefix.h
@@ -209,7 +209,7 @@ static __tb_inline__ tb_void_t xm_binutils_coff_write_symbol_name(tb_stream_ref_
* @param offset the string offset (from start of string table content, after size field)
* @return the string (static buffer, valid until next call)
*/
-static __tb_inline__ tb_bool_t xm_binutils_coff_read_string(tb_stream_ref_t istream, tb_uint32_t strtab_offset, tb_uint32_t offset, tb_char_t *name, tb_size_t name_size) {
+static __tb_inline__ tb_bool_t xm_binutils_coff_read_string(tb_stream_ref_t istream, tb_hize_t strtab_offset, tb_uint32_t offset, tb_char_t *name, tb_size_t name_size) {
tb_assert_and_check_return_val(istream && name && name_size > 0, tb_false);
// In COFF format, the offset in symbol table is from the start of string table
@@ -271,7 +271,7 @@ static __tb_inline__ tb_bool_t xm_binutils_coff_read_string(tb_stream_ref_t istr
* @param name_size the size of the buffer
* @return tb_true on success, tb_false on failure
*/
-static __tb_inline__ tb_bool_t xm_binutils_coff_get_symbol_name(tb_stream_ref_t istream, xm_coff_symbol_t const *sym, tb_uint32_t strtab_offset, tb_char_t *name, tb_size_t name_size) {
+static __tb_inline__ tb_bool_t xm_binutils_coff_get_symbol_name(tb_stream_ref_t istream, xm_coff_symbol_t const *sym, tb_hize_t strtab_offset, tb_char_t *name, tb_size_t name_size) {
tb_assert_and_check_return_val(istream && sym && name && name_size > 0, tb_false);
// check if it's a long name (first 4 bytes are zeros)
diff --git a/core/src/xmake/binutils/elf/readsyms.c b/core/src/xmake/binutils/elf/readsyms.c
index 7e7544bea..03756d240 100644
--- a/core/src/xmake/binutils/elf/readsyms.c
+++ b/core/src/xmake/binutils/elf/readsyms.c
@@ -66,8 +66,9 @@ tb_bool_t xm_binutils_elf_read_symbols_32(tb_stream_ref_t istream, tb_hize_t bas
symtab_section = section;
found_symtab = tb_true;
} else if (section.sh_type == XM_ELF_SHT_STRTAB && section.sh_link == 0) {
- // .strtab is linked from .symtab, but we need to find it
- // check if this is the string table for symbols
+ /* .strtab is linked from .symtab, but we need to find it
+ * check if this is the string table for symbols
+ */
if (found_symtab && symtab_section.sh_link == i) {
strtab_section = section;
found_strtab = tb_true;
diff --git a/core/src/xmake/binutils/mslib/extractlib.c b/core/src/xmake/binutils/mslib/extractlib.c
index 8912070ae..e6569ac3e 100644
--- a/core/src/xmake/binutils/mslib/extractlib.c
+++ b/core/src/xmake/binutils/mslib/extractlib.c
@@ -84,8 +84,9 @@ tb_bool_t xm_binutils_mslib_extract(tb_stream_ref_t istream, tb_char_t const *ou
return tb_false;
}
- // ensure output directory exists
- // check if directory already exists
+ /* ensure output directory exists
+ * check if directory already exists
+ */
if (!tb_file_info(outputdir, tb_null)) {
// directory doesn't exist, create it
if (!tb_directory_create(outputdir)) {
@@ -126,13 +127,15 @@ tb_bool_t xm_binutils_mslib_extract(tb_stream_ref_t istream, tb_char_t const *ou
// offset into long name table (/123)
tb_int64_t offset = xm_binutils_mslib_parse_decimal(header.name + 1, 15);
if (offset >= 0 && (tb_size_t)offset < longnames_size) {
- // copy from longnames
- // names in longnames are null-terminated
+ /* copy from longnames
+ * names in longnames are null-terminated
+ */
tb_strlcpy(member_name, longnames + offset, sizeof(member_name));
}
} else {
- // symbol table or other special member (/)
- // usually symbol table is just "/"
+ /* symbol table or other special member (/)
+ * usually symbol table is just "/"
+ */
tb_strlcpy(member_name, "/", sizeof(member_name));
}
} else {
@@ -164,9 +167,10 @@ tb_bool_t xm_binutils_mslib_extract(tb_stream_ref_t istream, tb_char_t const *ou
continue;
}
- // check if we should extract
- // skip empty names, symbol tables (/), long name table (//) - handled above,
- // and __.SYMDEF (SysV/BSD style symbol table, just in case)
+ /* check if we should extract
+ * skip empty names, symbol tables (/), long name table (//) - handled above,
+ * and __.SYMDEF (SysV/BSD style symbol table, just in case)
+ */
if (member_name[0] == '\0' || tb_strcmp(member_name, "/") == 0 || tb_strcmp(member_name, "//") == 0 ||
tb_strncmp(member_name, "__.SYMDEF", 9) == 0) {
@@ -185,8 +189,9 @@ tb_bool_t xm_binutils_mslib_extract(tb_stream_ref_t istream, tb_char_t const *ou
continue;
}
- // construct output path
- // replace \ with /
+ /* construct output path
+ * replace \ with /
+ */
tb_size_t name_len = tb_strlen(member_name);
for (tb_size_t i = 0; i < name_len; i++) {
if (member_name[i] == '\\') member_name[i] = '/';
diff --git a/core/src/xmake/binutils/mslib/readsyms.c b/core/src/xmake/binutils/mslib/readsyms.c
index c6fcc73f4..50d7aa416 100644
--- a/core/src/xmake/binutils/mslib/readsyms.c
+++ b/core/src/xmake/binutils/mslib/readsyms.c
@@ -210,13 +210,15 @@ tb_bool_t xm_binutils_mslib_read_symbols(tb_stream_ref_t istream, tb_hize_t base
// offset into long name table (/123)
tb_int64_t offset = xm_binutils_mslib_parse_decimal(header.name + 1, 15);
if (offset >= 0 && (tb_size_t)offset < longnames_size) {
- // copy from longnames
- // names in longnames are null-terminated
+ /* copy from longnames
+ * names in longnames are null-terminated
+ */
tb_strlcpy(member_name, longnames + offset, sizeof(member_name));
}
} else {
- // symbol table or other special member (/)
- // usually symbol table is just "/"
+ /* symbol table or other special member (/)
+ * usually symbol table is just "/"
+ */
tb_strlcpy(member_name, "/", sizeof(member_name));
}
} else {
@@ -249,8 +251,9 @@ tb_bool_t xm_binutils_mslib_read_symbols(tb_stream_ref_t istream, tb_hize_t base
}
// check if we should process
- // skip empty names, long name table (//) - handled above,
- // and __.SYMDEF (SysV/BSD style symbol table, just in case)
+ /* skip empty names, long name table (//) - handled above,
+ * and __.SYMDEF (SysV/BSD style symbol table, just in case)
+ */
if (member_name[0] == '\0' || tb_strcmp(member_name, "//") == 0 ||
tb_strncmp(member_name, "__.SYMDEF", 9) == 0) {