On this page

Most “assembler bugs” actually come from the environment: an invisible space in a Makefile, a 0x0D byte in a shebang, or a symbol that strip already removed.

In lesson 27, we covered the debugging tools. The final step is checking the testbed itself: which shell executes commands, which bytes sit at the start of a file, how Git checks out line endings, and what remains inside an ELF binary after preparing it for release.

Mental Model: File Bug vs. Environment Bug

Intuition What the testbed shows
make handles indentation like any editor A recipe must begin with a literal tab byte 0x09; four spaces trigger missing separator
Line endings work the same everywhere Windows text leaves a 0x0D byte behind, making the kernel look for /bin/sh\r
strip only shrinks the file It strips .symtab, leaving nm unable to find any local symbols
Editor settings are a personal preference .editorconfig and .vscode/settings.json enforce indentation and line endings across the team
An alias works as soon as it is saved in ~/.zshrc An already-running shell does not reload rc files, so type disasm returns not found

Makefile: Tab vs. Four Spaces

In broken-lab/, there are two nearly identical files. The difference is a single invisible character on the recipe line.

broken-lab/Makefile.broken
# SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0

# broken-lab/Makefile.broken — recipe indented with spaces.

all:
    @echo broken
broken-lab/Makefile.fixed
# SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0

# broken-lab/Makefile.fixed — the same recipe, indented with a tab.

all:
	@echo fixed

cat -A reveals non-printing bytes: $ marks end-of-line, ^I marks a tab, and ^M marks a carriage return.

$ cat -A broken-lab/Makefile.broken | tail -2
all:$
    @echo broken$
$ cat -A broken-lab/Makefile.fixed | tail -2
all:$
^I@echo fixed$

Running make confirms the issue is not the command text itself:

$ make -f broken-lab/Makefile.broken
broken-lab/Makefile.broken:6: *** missing separator.  Stop.
$ echo $?
2

The missing separator error is caused by leading spaces on the recipe line. Line 6 is @echo broken, not all:.

Why specifically a tab? By make syntax rules, a recipe is delimited from its target by 0x09, whereas a line with leading spaces is parsed as a continuation or a top-level construct. cat -A is the fastest way to spot the difference because ls, file, and an editor configured with soft tabs render both identically.

CRLF and the Shebang: The Byte You Cannot See

CRLF line endings break script execution. In a shebang, that stray byte becomes part of the interpreter path.

$ file broken-lab/hello_crlf
broken-lab/hello_crlf: POSIX shell script, ASCII text executable, with CRLF line terminators
$ ./broken-lab/hello_crlf
bash: ./broken-lab/hello_crlf: /bin/sh^M: bad interpreter: No such file or directory
$ echo $?
126

The ^M in the message is 0x0D: the kernel received the path /bin/sh\r and found no such file. Exit code 126 means “the file was found, but cannot be executed” (whereas 127 means “command not found”). The exact exit code depends on the invoking shell: bash returns 126, while zsh prints bad interpreter: /bin/sh^M: no such file or directory and returns 127, treating the failure as a missing command.

LF  (Linux):   23 21 2f 62 69 6e 2f 73 68 0a     #!/bin/sh\n
CRLF (Win):    23 21 2f 62 69 6e 2f 73 68 0d 0a  #!/bin/sh\r\n  ──► path "/bin/sh\r"

The fix is stripping \r from every line, not just the first:

$ sed -i 's/\r$//' broken-lab/hello_crlf
$ file broken-lab/hello_crlf
broken-lab/hello_crlf: POSIX shell script, ASCII text executable

To prevent the fixture from being silently “fixed” back on the next git checkout, you need a .gitattributes file. For the test fixture, the exception is targeted:

broken-lab/.gitattributes
# The CRLF fixture keeps its bytes: normalization would destroy the lesson.
hello_crlf -text -eol

-text disables text normalization, and -eol removes line-ending conversion. Without them, the root rule * text=auto eol=lf would rewrite the fixture to LF and hide the bug.

strip: What Actually Disappears from an ELF

broken-lab/symbols.c
/* SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0 */

#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>

static int32_t tooling_marker(int32_t value)
{
    return value * 3 + 1;
}

int main(void)
{
    printf("%" PRId32 "\n", tooling_marker(14));

    return 0;
}

The binary is compiled with -g, preserving function names and debug sections. A copy is then passed through strip.

$ nm build/symbols | grep tooling_marker
0000000000001139 t tooling_marker
$ nm build/symbols_stripped
nm: build/symbols_stripped: no symbols
$ readelf -SW build/symbols_stripped | grep -E 'symtab|dynsym'
  [ 4] .dynsym           DYNSYM          00000000000003e8 0003e8 0000a8 18   A  5   1  8
$ ./build/symbols_stripped
43
$ stat -c '%n %s bytes' build/symbols build/symbols_stripped
build/symbols 17416 bytes
build/symbols_stripped 14472 bytes

Fields and implications:

  • t in nm — a local symbol in .text; this is what GDB looks up by name.
  • nm: ... no symbols — .symtab is gone, so querying local symbol names returns nothing.
  • .dynsym survived — the dynamic linker still needs it to resolve imports such as printf and __libc_start_main.
  • 43 — the binary still runs fine: strip never touches executable instructions.
  • 17416 vs. 14472 — saving 2,944 bytes (nearly 3 KiB) comes purely from dropping symbol names and debug info.
build/symbols:          [ Headers | .text | .dynsym | .data | .symtab | .debug_* ]
build/symbols_stripped: [ Headers | .text | .dynsym | .data ]  (runs fine, nm is empty)

Practical takeaway: strip belongs on release artifacts, never on the build you hand to GDB. If you still need symbols for production crash analysis, split them out into a separate debug file rather than discarding them permanently.

Git, Editor, and Shell

These reference templates from lesson 28’s reference/ directory codify baseline rules that are error-prone to maintain by hand (the repository root holds expanded versions covering all lessons, while the hello_crlf exception lives in broken-lab/.gitattributes).

reference/.gitignore
# Build artifacts and crash dumps stay out of the repository.
build/
*.o
*.out
core
core.*
vgcore.*

# Python and editor caches.
__pycache__/
.cache/
.vscode/
# The exception keeps the lesson 27 workspace configs tracked.
!lessons/27-advanced-debugging/.vscode/
!lessons/27-advanced-debugging/.vscode/*.json

# Hugo output when the lesson is rendered next to the site.
public/
.hugo_build.lock
reference/.gitattributes
# Normalize text to LF in the repository and in working trees.
* text=auto eol=lf

*.c      text eol=lf
*.h      text eol=lf
*.asm    text eol=lf
*.S      text eol=lf
*.sh     text eol=lf
Makefile text eol=lf
*.md     text eol=lf
*.json   text eol=lf

# Fixtures that must keep their original bytes.
hello_crlf -text -eol
reference/.editorconfig
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{c,h,asm,inc,S}]
indent_style = space
indent_size = 4
max_line_length = 100

[{Makefile,*.mk}]
indent_style = tab
indent_size = 4

[*.{sh,json}]
indent_style = space
indent_size = 2

The [{Makefile,*.mk}] section is the only place with indent_style = tab: the editor inserts 0x09 in recipes automatically so you cannot accidentally corrupt a Makefile. Meanwhile, .asm, .c, and .h keep four spaces and a 100-column limit.

VS Code workspace settings mirror these rules inside the IDE:

reference/vscode-settings.json
{
  "files.eol": "\n",
  "files.insertFinalNewline": true,
  "files.trimTrailingWhitespace": true,
  "editor.rulers": [80, 100],
  "files.associations": {
    "*.asm": "asm-collection",
    "*.inc": "asm-collection"
  },
  "editor.detectIndentation": false,
  "editor.insertSpaces": true,
  "editor.tabSize": 4,
  "[makefile]": {
    "editor.insertSpaces": false,
    "editor.tabSize": 4
  }
}

Why these settings matter:

  • files.eol locks line endings to \n so newly created files never pick up CRLF, even on a Windows host.
  • files.insertFinalNewline and files.trimTrailingWhitespace eliminate two common sources of noisy diffs.
  • editor.detectIndentation: false stops the editor from guessing indentation from the first lines of a file.
  • [makefile].insertSpaces: false enforces hard tabs exclusively where make requires them.

Troubleshooting the shell aliases from lesson 02 starts with type: this shell builtin tells you whether a name resolves to an alias, function, or executable on disk.

$ type disasm
disasm not found

If aliases.sh is already sourced from ~/.zshrc yet the output stays not found, the running shell simply has not reloaded its config. Running source aliases.sh in the current session—or opening a fresh terminal—resolves it.

When working under WSL2, keep the repository inside the distro’s native filesystem (such as ~/asm-course) rather than under /mnt/c/.... Directories under /mnt/c cross the Windows filesystem bridge: file permissions and line endings behave differently, and builds are noticeably slower. VS Code with the Remote-WSL extension opens native Linux paths using the Linux toolchain directly, so .vscode/settings.json applies seamlessly.

Common Failures

  1. “My Makefile looks right, yet make prints missing separator.”
    Fact: cat -A shows @echo broken$ instead of ^I@echo fixed$, and make aborts on line 6.
    Cause: make requires a tab byte to mark a recipe; leading spaces are treated as plain text.
    Fix: Set indent_style = tab for Makefile in .editorconfig and inspect suspect lines with cat -A.

  2. “A CRLF script runs fine when I type sh script.sh.”
    Fact: ./broken-lab/hello_crlf fails with bad interpreter: /bin/sh^M, whereas sh broken-lab/hello_crlf prints hello.
    Cause: On direct execution, the kernel reads the entire shebang including 0x0D; when invoked explicitly with sh, the interpreter reads the script as input and tolerates trailing \r bytes.
    Fix: Strip \r with sed -i 's/\r$//' and protect intentional fixtures from normalization with -text -eol.

  3. “After strip, the binary stopped running.”
    Fact: nm build/symbols_stripped reports no symbols, yet the binary prints 43 and exits with code 0.
    Cause: strip drops .symtab and debug sections, not .text; execution only needs the dynamic loader and .dynsym.
    Fix: Never debug a stripped binary—keep an unstripped -g build or split debug info into a separate file.

  4. “The alias is in my rc file, so it must already work.”
    Fact: type disasm returns disasm not found, even though alias disasm=... is in the file.
    Cause: The shell only reads its rc file at startup; editing it does not affect already-open sessions.
    Fix: Run source aliases.sh or open a new terminal, and verify with type rather than grep.

Lab

Goal. Write env-check.sh to detect all three failure modes in broken-lab/ and distinguish the broken state from the fixed state.

Contract and constraints.

  • The script runs from the lesson directory and must not depend on the caller’s working directory.
  • Check 1: the recipe in broken-lab/Makefile.broken starts with spaces.
  • Check 2: broken-lab/hello_crlf contains 0x0D.
  • Check 3: the stripped copy of the binary contains no .symtab section.
  • Print one line per check; exit with code 0 when all three anomalies are detected, otherwise exit with 1.

Verification criteria.

  1. bash -n env-check.sh reports no syntax errors.
  2. ./env-check.sh prints three lines and exits with code 0.
  3. Replacing Makefile.broken with Makefile.fixed, the CRLF fixture with an LF copy, and the stripped binary with the unstripped one causes ./env-check.sh to exit with code 1.
  4. git status does not show build/, *.o, or core.*.
Hints, Expected Output, and Walkthrough

For the first check, matching leading spaces before @ on a recipe line is enough: grep -nP '^ +@' broken-lab/Makefile.broken. GNU grep’s -P flag enables Perl-compatible regular expressions (PCRE), so the pattern reads “start of line, one or more spaces, @” (POSIX -E works just as well for this simple pattern).

For the second check, scanning raw bytes is more reliable than parsing file output: grep -q $'\r' broken-lab/hello_crlf. ANSI-C quoting $'\r' produces a literal 0x0D byte rather than the two characters \ and r.

For the third check, inspect the stripped copy, not the unstripped binary. Escape the dot (readelf -SW build/symbols_stripped | grep -q '\.symtab') so the regex matches a literal . rather than any character: without the backslash, '.symtab' would match any name containing <char>symtab (such as .gnu.symtab or a path containing symtab). The escaped pattern gives the right result on both binaries: non-zero on build/symbols_stripped and zero on build/symbols. Checking build/symbols by mistake inverts the condition and triggers a false positive.

Expected output is three labeled status lines and exit code 0. On the fixed set, the script must return 1—proving it inspects actual state rather than printing canned text.

Testbed sources, Makefile, and automated tests for this lesson: lessons/28-tooling-troubleshooting.

Summary

  1. Makefile recipes must begin with a literal tab 0x09; leading spaces trigger missing separator before any shell runs.
  2. cat -A renders ^I, ^M, and $, making indentation and line endings visible.
  3. CRLF breaks shebangs because 0x0D becomes part of the interpreter path; .gitattributes with -text -eol preserves fixture bytes across checkouts.
  4. strip removes .symtab and debug info while leaving .text and .dynsym intact.
  5. .editorconfig and .vscode/settings.json standardize indentation, line endings, and editor behavior for the whole team.
  6. type checks whether the active shell sees an alias; editing an rc file requires source or a new session.

This course began in lesson 00 with two questions: why gcc -S output looks alien, and why the “one instruction = one cycle” myth breaks down. By lesson 28, that arc comes full circle: compiler output reads like ordinary code, every instruction carries a visible cycle and pipeline cost, every file operation maps to the VFS and syscall boundary, and crashes are diagnosed directly from registers, stack frames, and cache lines.

Course Complete
The x86-64 ASM course is complete. Next is hands-on practice: build your own testbed, run make test, and make sure none of the failures from lesson 26 creep in by accident. The cheatsheet in lesson 24, the ISA matrix in lesson 25, and the crash catalog in lesson 26 remain an engineer’s go-to reference whenever you hit a strange crash, a slow loop, or another -march=native surprise.