Skip to content

libiberty: return a copy of the name when lrealpath has no realpath - #37

Merged
codewiz merged 1 commit into
amiga16.2from
fix/lrealpath-fallback
Sep 8, 2026
Merged

codewiz merged 1 commit into
amiga16.2from
fix/lrealpath-fallback

Conversation

@codewiz

@codewiz codewiz commented Sep 7, 2026 •

Copy link
Copy Markdown
Member

lrealpath has no code path for a host without realpath, canonicalize_file_name or Win32: it falls off the end of the function. At -Os gcc compiles that into a bare rts, so on such a host both file names "canonicalize" to whatever happens to be in d0 and canonical_filename_eq reports them equal. The AmigaOS-hosted driver then refused every -o:

m68k-amigaos-gcc: fatal error: input file 'hello.o' is the same as output file

Return a copy of the name instead, which is what the other fallbacks do when their canonicalization fails.

Found while chasing the AmigaOS-hosted gcc crash reported for the AmigaOS-hosted package; libnix now provides realpath, so with a current libnix this fallback is no longer reached on AmigaOS, but it keeps libiberty correct on any host that lacks it. Same fix for the binutils copy: AmigaPorts/binutils-gdb#20. libnix realpath: AmigaPorts/libnix#15.

On hosts without realpath, canonicalize_file_name or _WIN32 the function
fell off its end, so gcc at -Os compiled it to a bare rts and "input file
is the same as output file" fired on every -o.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is minimal, well-scoped, and resolves a clear undefined-behavior bug by aligning the final fallback behavior with existing failure paths that already return a duplicated filename.

Pull request overview

This PR fixes an undefined-behavior bug in libiberty’s lrealpath() on hosts that lack any supported canonicalization mechanism (realpath, canonicalize_file_name, or Win32 APIs). Previously, the function could fall off the end without returning a value, causing callers like canonical_filename_eq to behave incorrectly (e.g., treating unrelated paths as equal).

Changes:

  • Add a final fallback in lrealpath() to return strdup(filename) when no canonicalization method is available.
  • Document (in-code) why returning a copy is required to avoid undefined return values and incorrect equality comparisons.
File summaries
File Description
libiberty/lrealpath.c Adds a safe final fallback return path to prevent undefined behavior when no canonicalization APIs exist on the host.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codewiz
codewiz merged commit aba13a5 into amiga16.2 Sep 8, 2026
1 check passed
@codewiz
codewiz deleted the fix/lrealpath-fallback branch September 8, 2026 11:04
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.

3 participants