summaryrefslogtreecommitdiff
path: root/core/src/xmake/binutils/coff
diff options
context:
space:
mode:
authorruki <[email protected]>2025-12-09 00:36:15 +0800
committerruki <[email protected]>2025-12-09 00:36:15 +0800
commit2ce4dfa1c8029498cfa6b99ed28daca6c2e350d4 (patch)
treef9039bb89eb1fcc98924d495e2dc1e6e305ef0ee /core/src/xmake/binutils/coff
parent333af0b66dfe73fabb2c900bce00ba2d50bfe622 (diff)
improve symbol type
Diffstat (limited to 'core/src/xmake/binutils/coff')
-rw-r--r--core/src/xmake/binutils/coff/prefix.h35
-rw-r--r--core/src/xmake/binutils/coff/readsyms.c17
2 files changed, 38 insertions, 14 deletions
diff --git a/core/src/xmake/binutils/coff/prefix.h b/core/src/xmake/binutils/coff/prefix.h
index 95737dc20..ccc7f6292 100644
--- a/core/src/xmake/binutils/coff/prefix.h
+++ b/core/src/xmake/binutils/coff/prefix.h
@@ -258,20 +258,31 @@ static __tb_inline__ tb_bool_t xm_binutils_coff_get_symbol_name(tb_stream_ref_t
}
}
-/* get symbol type string from storage class
+/* get symbol type character (nm-style) from COFF symbol
*
- * @param scl the storage class
- * @return the type string
+ * @param scl the storage class
+ * @param sect the section number (0 = undefined)
+ * @return the type character (T/t/D/d/B/b/U)
*/
-static __tb_inline__ tb_char_t const *xm_binutils_coff_get_symbol_type(tb_uint8_t scl) {
- // IMAGE_SYM_CLASS_EXTERNAL = 2
- // IMAGE_SYM_CLASS_STATIC = 3
- // IMAGE_SYM_CLASS_LABEL = 6
- switch (scl) {
- case 2: return "external";
- case 3: return "static";
- case 6: return "label";
- default: return "unknown";
+static __tb_inline__ tb_char_t xm_binutils_coff_get_symbol_type_char(tb_uint8_t scl, tb_int16_t sect) {
+ // undefined symbol
+ if (sect == 0) {
+ return 'U';
+ }
+
+ // check if external
+ tb_bool_t is_external = (scl == 2); // IMAGE_SYM_CLASS_EXTERNAL
+
+ // For COFF, section 1 is usually .text, section 2 is .data, section 3 is .bss
+ // This is a heuristic and may not be 100% accurate
+ if (sect == 1) {
+ return is_external ? 'T' : 't'; // text section
+ } else if (sect == 2) {
+ return is_external ? 'D' : 'd'; // data section
+ } else if (sect == 3) {
+ return is_external ? 'B' : 'b'; // bss section
+ } else {
+ return is_external ? 'S' : 's'; // other section
}
}
diff --git a/core/src/xmake/binutils/coff/readsyms.c b/core/src/xmake/binutils/coff/readsyms.c
index d863c2fdf..abe374367 100644
--- a/core/src/xmake/binutils/coff/readsyms.c
+++ b/core/src/xmake/binutils/coff/readsyms.c
@@ -84,6 +84,17 @@ tb_bool_t xm_binutils_coff_read_symbols(tb_stream_ref_t istream, lua_State *lua)
}
continue;
}
+
+ // skip internal symbols (starting with .)
+ if (name[0] == '.') {
+ sym_index++;
+ if (sym.naux > 0) {
+ sym_index += sym.naux; // skip auxiliary entries
+ // skip auxiliary data
+ tb_stream_seek(istream, tb_stream_offset(istream) + sym.naux * 18);
+ }
+ continue;
+ }
// create symbol table entry
lua_pushinteger(lua, sym_count + 1);
@@ -104,9 +115,11 @@ tb_bool_t xm_binutils_coff_read_symbols(tb_stream_ref_t istream, lua_State *lua)
lua_pushinteger(lua, sym.sect);
lua_settable(lua, -3);
- // type
+ // type (nm-style: T/t/D/d/B/b/U)
+ tb_char_t type_char = xm_binutils_coff_get_symbol_type_char(sym.scl, sym.sect);
+ tb_char_t type_str[2] = {type_char, '\0'};
lua_pushstring(lua, "type");
- lua_pushstring(lua, xm_binutils_coff_get_symbol_type(sym.scl));
+ lua_pushstring(lua, type_str);
lua_settable(lua, -3);
// storage class