Skip to content

Build mode detection via NDEBUG has unintended side effects #1386

@nmeum

Description

@nmeum

Commit 6ddf46b fixed a stack overflow on the interrupt stack in debug mode by increasing the size of that stack in debug build mode. The debug build mode is detected by the absence of the NDEBUG macro (which is defined in release mode):

conf-opt = -O2 -DNDEBUG

This is hacky but at least for the arch-switch.hh header it works as this header is only included from core/, which is compiled with the mode-specific CFLAGS. However, for the arch-cpu.hh header this approach doesn't work at all because this header is included from osv/sched.hh which part of the public API:

#include "arch-cpu.hh"

Therefore, every software which includes osv/sched.hh must also compile with the mode-specific CFLAGS (e.g., include NDEBUG in release mode), which isn't necessarily the case. As such, code in core/* and application code will disagree on sizeof(arch_thread) and this causes very hard to debug bugs since arch_thread is part of sched::thread:

arch_thread _arch;

As a result, code in core/* and application code will disagree on struct member offsets beyond _arch, causing hard to debug memory corruptions.


Noticed this due to broken stat counters while rebasing #1338.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions