Skip to content

Fix build dependencies and compiler warnings on Ubuntu 24.04#1

Open
SerErris wants to merge 1 commit into
lvitals:mainfrom
SerErris:segfault-issue
Open

Fix build dependencies and compiler warnings on Ubuntu 24.04#1
SerErris wants to merge 1 commit into
lvitals:mainfrom
SerErris:segfault-issue

Conversation

@SerErris
Copy link
Copy Markdown

@SerErris SerErris commented Apr 7, 2026

Proposed Changes: Fix Build Dependencies, gettext Warnings, and Segfault

This PR addresses several issues encountered when building and testing on Ubuntu 24.04. The changes focus on build system reliability and modern compiler compatibility.

1. Build System: Explicit Dependency for Tests

Issue: When running a parallel build or calling make all, the test targets (e.g., pass_test) were attempted before the z80asm binary was actually compiled. This resulted in Error 127 because the shell could not find the executable in the build directory.
Fix: Updated CMakeLists.txt to ensure that all test targets explicitly depend on the z80asm executable target. This guarantees the binary is physically present before the test suite enters the Trugraum of execution.

2. CMake: Improved libintl Detection

Issue: On modern Linux systems, libintl is often built directly into glibc rather than existing as a separate library file. The previous CMake configuration failed to recognize this, leading to linking issues.
Fix: Modified CMakeLists.txt to use a more robust detection method that checks if the required internationalization symbols are available in the standard library before attempting to link an external intl library.

3. Compiler Warnings: gettext.h Refactoring

Issue: The macro definitions in include/gettext.h for bindtextdomain and textdomain were casting arguments to (const char *) without a consuming operation. Modern GCC/Clang compilers flag this with -Wunused-value warnings (e.g., “statement with no effect”).
Fix: Refactored the fallback macros in include/gettext.h to remove the unnecessary return-value casts when NLS (Native Language Support) is disabled. This cleans up the build log and allows for stricter "Warnings-as-Errors" configurations.

4. Stability: files.c Segmentation Fault

Issue: Fixed a segmentation fault occurring during specific file access patterns.
Fix: Added null-pointer checks and sanitized pointer dereferences in src/files.c to prevent the application from crashing during file I/O operations.


Verification

  • Compiler Cleanliness: Successfully compiled on Ubuntu 24.04 with zero warnings.
  • Build Order: Verified that make now correctly builds the z80asm binary before executing the test suite, resolving the previous file-not-found errors.
  • Test Suite: Passed all automated tests, including regression tests for known bugs.
  • NLS Support: Confirmed that translations still function (or fail gracefully) depending on the presence of libintl.

Build and Test Log:

chris@Tinuviel:~/z80tst/build$ make
[ 12%] Built target translations
[ 16%] Building C object src/CMakeFiles/z80asm.dir/main.c.o
[ 20%] Building C object src/CMakeFiles/z80asm.dir/files.c.o
[ 25%] Building C object src/CMakeFiles/z80asm.dir/stack.c.o
[ 29%] Building C object src/CMakeFiles/z80asm.dir/z80asm.c.o
[ 33%] Building C object src/CMakeFiles/z80asm.dir/expressions.c.o
[ 37%] Building C object src/CMakeFiles/z80asm.dir/stringstore.c.o
[ 41%] Building C object src/CMakeFiles/z80asm.dir/error.c.o
[ 45%] Linking C executable z80asm
[ 45%] Built target z80asm
[ 50%] Compiling and verifying pass.asm
[ 50%] Built target pass_test
[ 54%] Compiling and verifying patch9377.asm
[ 54%] Built target patch9377_test
[ 58%] Compiling and verifying bug26772.asm
[ 58%] Built target bug26772_test
[ 62%] Compiling and verifying bug47653.asm
[ 62%] Built target bug47653_test
[ 66%] Compiling and verifying bug60151.asm
[ 66%] Built target bug60151_test
[ 70%] Compiling and verifying bug55596.asm
[ 70%] Built target bug55596_test
[ 75%] Building C object compat/CMakeFiles/compat.dir/getopt.c.o
[ 79%] Building C object compat/CMakeFiles/compat.dir/getopt1.c.o
[ 83%] Building C object compat/CMakeFiles/compat.dir/malloc.c.o
[ 87%] Building C object compat/CMakeFiles/compat.dir/realloc.c.o
[ 91%] Linking C static library libcompat.a
[ 91%] Built target compat
[ 95%] Compiling hello.asm to hello.rom
[ 95%] Built target hello
[100%] Compiling macro.asm to macro.rom
[100%] Built target macro

…ild logic

Description:
This commit addresses several stability and build-system issues discovered on Ubuntu 24.04:

src/files.c: Fixed a segmentation fault occurring during file handling/pointer dereferencing.

src/gettext.h: Resolved compiler warnings by ensuring macro definitions don't conflict with system headers.

CMakeLists.txt:

Improved libintl recognition to ensure translations link correctly on modern Linux distributions.

Added an explicit dependency for the test suite. Previously, tests would attempt to run before the z80asm binary was actually compiled, leading to Error 127.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant