summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
authorruki <[email protected]>2025-12-09 00:44:23 +0800
committerruki <[email protected]>2025-12-09 00:44:23 +0800
commit5381ba967a7484f49c3dd3fb75e6443bacb74f46 (patch)
treece4169c772250b8792b9e2501402414658a1e732 /core/src
parentb5b4ed3cf17b9c3d11e24d16e3fe692377ecaf95 (diff)
format code
Diffstat (limited to 'core/src')
-rw-r--r--core/src/xmake/binutils/coff/prefix.h22
-rw-r--r--core/src/xmake/binutils/elf/prefix.h12
-rw-r--r--core/src/xmake/binutils/macho/prefix.h12
-rw-r--r--core/src/xmake/binutils/prefix.h28
4 files changed, 37 insertions, 37 deletions
diff --git a/core/src/xmake/binutils/coff/prefix.h b/core/src/xmake/binutils/coff/prefix.h
index 1b1c2298e..b9732a4ec 100644
--- a/core/src/xmake/binutils/coff/prefix.h
+++ b/core/src/xmake/binutils/coff/prefix.h
@@ -189,11 +189,11 @@ static __tb_inline__ tb_void_t xm_binutils_coff_write_symbol_name(tb_stream_ref_
*/
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) {
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
// (including the 4-byte size field). So offset=4 points to the first string after
// the size field, offset=74 points to a string at position 74 from the start.
-
+
// read string table size first to validate offset
tb_uint32_t strtab_size = 0;
tb_hize_t saved_pos = tb_stream_offset(istream);
@@ -204,13 +204,13 @@ static __tb_inline__ tb_bool_t xm_binutils_coff_read_string(tb_stream_ref_t istr
tb_stream_seek(istream, saved_pos);
return tb_false;
}
-
+
// check offset (must be >= 4 to skip the size field, and < strtab_size)
if (offset < 4 || offset >= strtab_size) {
tb_stream_seek(istream, saved_pos);
return tb_false;
}
-
+
// seek to string position (offset is from start of string table, including size field)
// strtab_offset points to the start of string table (including 4-byte size field)
// offset is from the start of string table (including size field)
@@ -219,7 +219,7 @@ static __tb_inline__ tb_bool_t xm_binutils_coff_read_string(tb_stream_ref_t istr
tb_stream_seek(istream, saved_pos);
return tb_false;
}
-
+
// read string
tb_size_t pos = 0;
tb_byte_t c;
@@ -234,7 +234,7 @@ static __tb_inline__ tb_bool_t xm_binutils_coff_read_string(tb_stream_ref_t istr
name[pos++] = (tb_char_t)c;
}
name[pos] = '\0';
-
+
// restore position
tb_stream_seek(istream, saved_pos);
return tb_true;
@@ -251,7 +251,7 @@ static __tb_inline__ tb_bool_t xm_binutils_coff_read_string(tb_stream_ref_t istr
*/
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) {
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)
if (sym->n.longname.zeros == 0) {
// long name: read from string table
@@ -283,10 +283,10 @@ static __tb_inline__ tb_char_t xm_binutils_coff_get_symbol_type_char(tb_uint8_t
if (sect == 0) {
return 'U';
}
-
+
// check if external
tb_bool_t is_external = (scl == 2); // IMAGE_SYM_CLASS_EXTERNAL
-
+
// check section flags to determine type
if (sections && sect > 0 && sect <= nsects) {
tb_uint32_t flags = sections[sect - 1].flags; // section numbers are 1-based
@@ -303,7 +303,7 @@ static __tb_inline__ tb_char_t xm_binutils_coff_get_symbol_type_char(tb_uint8_t
return is_external ? 'D' : 'd'; // data section
}
}
-
+
// fallback: use section number heuristic
if (sect == 1) {
return is_external ? 'T' : 't'; // text section
@@ -312,7 +312,7 @@ static __tb_inline__ tb_char_t xm_binutils_coff_get_symbol_type_char(tb_uint8_t
} else if (sect == 3) {
return is_external ? 'B' : 'b'; // bss section
}
-
+
return is_external ? 'S' : 's'; // other section
}
diff --git a/core/src/xmake/binutils/elf/prefix.h b/core/src/xmake/binutils/elf/prefix.h
index 7ddc0ef85..6eba9ac51 100644
--- a/core/src/xmake/binutils/elf/prefix.h
+++ b/core/src/xmake/binutils/elf/prefix.h
@@ -279,12 +279,12 @@ static __tb_inline__ tb_bool_t xm_binutils_elf_is_64bit(tb_char_t const *arch) {
*/
static __tb_inline__ tb_bool_t xm_binutils_elf_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) {
tb_assert_and_check_return_val(istream && name && name_size > 0, tb_false);
-
+
tb_hize_t saved_pos = tb_stream_offset(istream);
if (!tb_stream_seek(istream, strtab_offset + offset)) {
return tb_false;
}
-
+
tb_size_t pos = 0;
tb_byte_t c;
while (pos < name_size - 1) {
@@ -298,7 +298,7 @@ static __tb_inline__ tb_bool_t xm_binutils_elf_read_string(tb_stream_ref_t istre
name[pos++] = (tb_char_t)c;
}
name[pos] = '\0';
-
+
tb_stream_seek(istream, saved_pos);
return tb_true;
}
@@ -314,11 +314,11 @@ static __tb_inline__ tb_char_t xm_binutils_elf_get_symbol_type_char(tb_uint8_t s
if (st_shndx == 0) {
return 'U';
}
-
+
// check bind (global = uppercase, local = lowercase)
tb_uint8_t bind = (st_info >> 4) & 0xf;
tb_bool_t is_global = (bind == 1); // STB_GLOBAL
-
+
// check type
tb_uint8_t type = st_info & 0xf;
if (type == 2) { // STT_FUNC
@@ -329,7 +329,7 @@ static __tb_inline__ tb_char_t xm_binutils_elf_get_symbol_type_char(tb_uint8_t s
// This is a heuristic - in practice, we'd need to check section flags
return is_global ? 'D' : 'd'; // data (assume data section)
}
-
+
// other types
return is_global ? 'S' : 's'; // other section
}
diff --git a/core/src/xmake/binutils/macho/prefix.h b/core/src/xmake/binutils/macho/prefix.h
index 7664940b1..0b0ea00c3 100644
--- a/core/src/xmake/binutils/macho/prefix.h
+++ b/core/src/xmake/binutils/macho/prefix.h
@@ -333,13 +333,13 @@ static __tb_inline__ tb_uint32_t xm_binutils_macho_parse_version(tb_char_t const
*/
static __tb_inline__ tb_bool_t xm_binutils_macho_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) {
tb_assert_and_check_return_val(istream && name && name_size > 0, tb_false);
-
+
tb_hize_t saved_pos = tb_stream_offset(istream);
// nlist.strx is offset from string table start (including 4-byte size field)
if (!tb_stream_seek(istream, strtab_offset + offset)) {
return tb_false;
}
-
+
tb_size_t pos = 0;
tb_byte_t c;
while (pos < name_size - 1) {
@@ -353,7 +353,7 @@ static __tb_inline__ tb_bool_t xm_binutils_macho_read_string(tb_stream_ref_t ist
name[pos++] = (tb_char_t)c;
}
name[pos] = '\0';
-
+
tb_stream_seek(istream, saved_pos);
return tb_true;
}
@@ -369,10 +369,10 @@ static __tb_inline__ tb_char_t xm_binutils_macho_get_symbol_type_char(tb_uint8_t
if (sect == 0) {
return 'U';
}
-
+
// check if external
tb_bool_t is_external = (type & XM_MACHO_N_EXT) != 0;
-
+
// check if in section
tb_uint8_t n_type = type & XM_MACHO_N_TYPE_MASK;
if (n_type == XM_MACHO_N_TYPE_SECT) {
@@ -391,7 +391,7 @@ static __tb_inline__ tb_char_t xm_binutils_macho_get_symbol_type_char(tb_uint8_t
return is_external ? 'S' : 's'; // other section
}
}
-
+
return '?'; // unknown
}
diff --git a/core/src/xmake/binutils/prefix.h b/core/src/xmake/binutils/prefix.h
index 74cef7cfe..048e74ee2 100644
--- a/core/src/xmake/binutils/prefix.h
+++ b/core/src/xmake/binutils/prefix.h
@@ -54,17 +54,17 @@
*/
static __tb_inline__ tb_bool_t xm_binutils_read_magic(tb_stream_ref_t istream, tb_uint8_t *magic, tb_size_t size) {
tb_assert_and_check_return_val(istream && magic && size > 0, tb_false);
-
+
tb_hize_t saved_pos = tb_stream_offset(istream);
if (!tb_stream_seek(istream, 0)) {
return tb_false;
}
-
+
tb_bool_t ok = tb_false;
if (tb_stream_bread(istream, magic, size)) {
ok = tb_true;
}
-
+
tb_stream_seek(istream, saved_pos);
return ok;
}
@@ -72,25 +72,25 @@ static __tb_inline__ tb_bool_t xm_binutils_read_magic(tb_stream_ref_t istream, t
/* detect object file format from stream
*
* @param istream the input stream
- * @return XM_BINUTILS_FORMAT_COFF, XM_BINUTILS_FORMAT_ELF, XM_BINUTILS_FORMAT_MACHO,
+ * @return XM_BINUTILS_FORMAT_COFF, XM_BINUTILS_FORMAT_ELF, XM_BINUTILS_FORMAT_MACHO,
* XM_BINUTILS_FORMAT_UNKNOWN, or -1 on error
*/
static __tb_inline__ tb_int_t xm_binutils_detect_format(tb_stream_ref_t istream) {
tb_assert_and_check_return_val(istream, -1);
-
+
// read magic bytes
tb_uint8_t magic[4];
if (!xm_binutils_read_magic(istream, magic, 4)) {
return -1;
}
-
+
// check ELF magic (0x7f 'E' 'L' 'F')
if (magic[0] == 0x7f && magic[1] == 'E' && magic[2] == 'L' && magic[3] == 'F') {
return XM_BINUTILS_FORMAT_ELF;
}
-
+
// check Mach-O magic
- if (magic[0] == 0xfe && magic[1] == 0xed && magic[2] == 0xfa &&
+ if (magic[0] == 0xfe && magic[1] == 0xed && magic[2] == 0xfa &&
(magic[3] == 0xce || magic[3] == 0xcf)) {
return XM_BINUTILS_FORMAT_MACHO; // Mach-O 32/64 (big endian)
}
@@ -100,7 +100,7 @@ static __tb_inline__ tb_int_t xm_binutils_detect_format(tb_stream_ref_t istream)
if (magic[0] == 0xcf && magic[1] == 0xfa && magic[2] == 0xed && magic[3] == 0xfe) {
return XM_BINUTILS_FORMAT_MACHO; // Mach-O 64 (little endian)
}
-
+
// check COFF (object files start with machine type, not a magic number)
// COFF header: machine (2 bytes) + nsects (2 bytes) + time (4 bytes) + ...
// Read machine type to verify if it's a valid COFF file
@@ -114,15 +114,15 @@ static __tb_inline__ tb_int_t xm_binutils_detect_format(tb_stream_ref_t istream)
return -1;
}
tb_stream_seek(istream, saved_pos);
-
+
// check if it's a valid COFF machine type
- if (machine == XM_BINUTILS_COFF_MACHINE_I386 ||
- machine == XM_BINUTILS_COFF_MACHINE_AMD64 ||
- machine == XM_BINUTILS_COFF_MACHINE_ARM ||
+ if (machine == XM_BINUTILS_COFF_MACHINE_I386 ||
+ machine == XM_BINUTILS_COFF_MACHINE_AMD64 ||
+ machine == XM_BINUTILS_COFF_MACHINE_ARM ||
machine == XM_BINUTILS_COFF_MACHINE_ARM64) {
return XM_BINUTILS_FORMAT_COFF;
}
-
+
// unknown format
return XM_BINUTILS_FORMAT_UNKNOWN;
}