[nasm:master] output/elf: Don't set data symbol type/size in ABS sections

nasm-bot for Fabian Giesen fabian.giesen at epicgames.com
Mon Nov 7 17:12:27 PST 2022

Commit-ID:  04f981e0e698161a27054795b837ff077eb666c8
Gitweb:     http://repo.or.cz/w/nasm.git?a=commitdiff;h=04f981e0e698161a27054795b837ff077eb666c8
Author:     Fabian Giesen <fabian.giesen at epicgames.com>
AuthorDate: Tue, 30 Aug 2022 14:20:09 -0700
Committer:  Fabian Giesen <fabian.giesen at epicgames.com>
CommitDate: Tue, 30 Aug 2022 14:26:54 -0700

output/elf: Don't set data symbol type/size in ABS sections

I'm dealing with a FreeBSD-derived embedded target that ends up
showing such symbols (which is mainly NASM struct definitions)
in backtraces after calling NULL function pointers, since these
symbols _are_ technically covering bytes around address zero.

Needless to say, this is extremely confusing and generates
nonsensical bug reports. (Essentially, random unrelated crashes
get cross-referenced to a random ASM struct, whatever the linker
picked for address 0).

These symbols are already a bit strange to begin with (they're
purely an artifact of how NASM happens to implement structs),
leaving their sizes at 0 seems reasonable.

Signed-off-by: Fabian Giesen <fabian.giesen at epicgames.com>

 output/outelf.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/output/outelf.c b/output/outelf.c
index f47728ed..34fb4ce5 100644
--- a/output/outelf.c
+++ b/output/outelf.c
@@ -2696,7 +2696,11 @@ static void debug_typevalue(int32_t type)
             stype = STT_NOTYPE;
-    if (stype == STT_OBJECT && lastsym && !lastsym->type) {
+    /* Set type and size info on most recently seen symbol if we haven't set it already.
+       But avoid setting size info on object (data) symbols in absolute sections (which
+       is primarily structs); some environments get confused with non-zero-extent absolute
+       object symbols and end up showing them in backtraces for NULL fn pointer calls. */
+    if (stype == STT_OBJECT && lastsym && !lastsym->type && lastsym->section != XSHN_ABS) {
         lastsym->size = ssize;
         lastsym->type = stype;

More information about the Nasm-commits mailing list