Most “assembler bugs” actually come from the environment: an invisible space in a
Makefile, a0x0Dbyte in a shebang, or a symbol thatstripalready 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.
# SPDX-License-Identifier: PolyForm-Noncommercial-1.0.0
# broken-lab/Makefile.broken — recipe indented with spaces.
all:
@echo broken
# 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 $?
2The 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 $?
126The ^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 executableTo 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:
# 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
/* 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 bytesFields and implications:
tinnm— a local symbol in.text; this is what GDB looks up by name.nm: ... no symbols—.symtabis gone, so querying local symbol names returns nothing..dynsymsurvived — the dynamic linker still needs it to resolve imports such asprintfand__libc_start_main.43— the binary still runs fine:stripnever touches executable instructions.17416vs.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).
# 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# 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 -eolroot = 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 = 2The [{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:
{
"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.eollocks line endings to\nso newly created files never pick up CRLF, even on a Windows host.files.insertFinalNewlineandfiles.trimTrailingWhitespaceeliminate two common sources of noisy diffs.editor.detectIndentation: falsestops the editor from guessing indentation from the first lines of a file.[makefile].insertSpaces: falseenforces hard tabs exclusively wheremakerequires 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 foundIf 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
-
“My
Makefilelooks right, yetmakeprintsmissing separator.”
Fact:cat -Ashows@echo broken$instead of^I@echo fixed$, andmakeaborts on line 6.
Cause:makerequires a tab byte to mark a recipe; leading spaces are treated as plain text.
Fix: Setindent_style = tabforMakefilein.editorconfigand inspect suspect lines withcat -A. -
“A CRLF script runs fine when I type
sh script.sh.”
Fact:./broken-lab/hello_crlffails withbad interpreter: /bin/sh^M, whereassh broken-lab/hello_crlfprintshello.
Cause: On direct execution, the kernel reads the entire shebang including0x0D; when invoked explicitly withsh, the interpreter reads the script as input and tolerates trailing\rbytes.
Fix: Strip\rwithsed -i 's/\r$//'and protect intentional fixtures from normalization with-text -eol. -
“After
strip, the binary stopped running.”
Fact:nm build/symbols_strippedreportsno symbols, yet the binary prints43and exits with code 0.
Cause:stripdrops.symtaband debug sections, not.text; execution only needs the dynamic loader and.dynsym.
Fix: Never debug a stripped binary—keep an unstripped-gbuild or split debug info into a separate file. -
“The alias is in my rc file, so it must already work.”
Fact:type disasmreturnsdisasm not found, even thoughalias disasm=...is in the file.
Cause: The shell only reads its rc file at startup; editing it does not affect already-open sessions.
Fix: Runsource aliases.shor open a new terminal, and verify withtyperather thangrep.
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.brokenstarts with spaces. - Check 2:
broken-lab/hello_crlfcontains0x0D. - Check 3: the stripped copy of the binary contains no
.symtabsection. - Print one line per check; exit with code 0 when all three anomalies are detected, otherwise exit with 1.
Verification criteria.
bash -n env-check.shreports no syntax errors../env-check.shprints three lines and exits with code 0.- Replacing
Makefile.brokenwithMakefile.fixed, the CRLF fixture with an LF copy, and the stripped binary with the unstripped one causes./env-check.shto exit with code 1. git statusdoes not showbuild/,*.o, orcore.*.
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
Makefilerecipes must begin with a literal tab0x09; leading spaces triggermissing separatorbefore any shell runs.cat -Arenders^I,^M, and$, making indentation and line endings visible.- CRLF breaks shebangs because
0x0Dbecomes part of the interpreter path;.gitattributeswith-text -eolpreserves fixture bytes across checkouts. stripremoves.symtaband debug info while leaving.textand.dynsymintact..editorconfigand.vscode/settings.jsonstandardize indentation, line endings, and editor behavior for the whole team.typechecks whether the active shell sees an alias; editing an rc file requiressourceor 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.
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.