Skip to content

AmigaOS host: locate the SDK relative to the executable - #39

Open
codewiz wants to merge 6 commits into
amiga16.2from
progdir-prefix
Open

codewiz wants to merge 6 commits into
amiga16.2from
progdir-prefix

Conversation

@codewiz

@codewiz codewiz commented Sep 8, 2026

Copy link
Copy Markdown
Member

Follow-up to #38: make the AmigaOS-hosted gcc find its own directories the way every other host does, instead of through a hardcoded GCC: assign and a spec function that reverse-engineered the prefix.

What changes

  • libiberty: restore the upstream make-relative-prefix.c, then add a small __amiga__ block: when argv[0] is a bare name, resolve PROGDIR: with GetProgramDir/NameFromLock and use that as the program path. The AmigaDOS shell keeps its search path in the process, not in PATH, so the upstream PATH walk finds nothing there. The result is a real path because it is handed to child processes whose own PROGDIR: is a different directory. No argv[0] rewriting, so nothing changes for symlinked programs.
  • gcc: PATH_SEPARATOR ';' on the AmigaOS host via a new xm-amigaos.h: a colon ends a volume or assign name, so splitting COMPILER_PATH or PATH on it breaks every element. collect2 goes back to plain prefix_from_env ("PATH"); the driver's environment reaches it through the local variables libnix's setenv now mirrors (setenv: mirror the environment into local variables libnix#16).
  • m68k-amigaos: %:find-file instead of sdk_root. find-file searches the startfile prefixes, which include <prefix>/m68k-amigaos/lib/, so ../libnix/include, ../clib2/lib and friends resolve from there. The sdk_root function, its hand-written /../ normalizer and the GCC: include dirs are gone; the hosted compiler keeps the cross layout via CROSS_DIRECTORY_STRUCTURE and finds everything relative to the executable. The generic -isystem <prefix>/include and -L <prefix>/lib entries are dropped: those directories hold nothing for the target, the driver already searches m68k-amigaos/include and lib, and translated to find-file they resolved from the runtime's -B directory and put m68k-amigaos/lib ahead of clib2/lib, so -mcrt=clib2 linked the wrong libc.a.

Tested

Linux cross compiler rebuilt and installed from this branch: hello world with -noixemul, -mcrt=nix13, -mcrt=clib2 and a C++ program with libnix all compile, link and run under vamos, and -v shows every include and library directory resolving under m68k-amigaos/.

AmigaOS-hosted compiler rebuilt from this branch and run under vamos with the prefix mounted as a plain volume and no GCC: assign: gcc:bin/m68k-amigaos-gcc resolves itself through PROGDIR:, derives every prefix from it (COLLECT_LTO_WRAPPER=gcc:bin/../libexec/..., -B gcc:bin/../lib/gcc/.../m68k-amigaos/lib/../libnix/lib/), and a C program with libnix, one with clib2 and a C++ program all compile, link through collect2 and run.

Known limit for the real AmigaOS host: the resolved paths contain .. components (m68k-amigaos/lib/../libnix/include), which AmigaDOS does not understand, so libnix needs to translate .. in paths before this works outside vamos. That is a libnix change, tracked separately.

The rewrite ignored progname, located the executable through
/proc/self/exe or a hardcoded GCC: and then stripped a fixed number of
components, so it only ever worked for a program in bin/. Bring back the
upstream algorithm, which matches the trailing components of progname
against the configured bin prefix and works at any depth.
A colon ends an AmigaDOS volume or assign name, so splitting COMPILER_PATH
or PATH on it breaks every element. Give the AmigaOS host an xm header
with PATH_SEPARATOR ';' and drop the collect2 workaround that hardcoded
GCC:bin instead of reading PATH: the driver's environment now reaches
collect2 through the local variables libnix's setenv mirrors.
The shell keeps its search path in the process rather than in PATH, so
make_relative_prefix cannot find a program given by bare name. AmigaOS
records the directory a program was loaded from as PROGDIR:; resolve it
to a real path with NameFromLock, since the result is handed to child
processes whose own PROGDIR: differs.
The sdk_root spec function computed the SDK root from the libexec prefix
and normalized the '/../' it produced by hand. The driver's find-file
already searches the startfile prefixes, which include
<prefix>/m68k-amigaos/lib/, so the libnix, clib2, ixemul and NDK
directories are reachable from there with plain relative paths. Drop
sdk_root and the GCC: assign hardcoded for the AmigaOS host: the hosted
compiler keeps the cross layout and finds everything relative to the
executable.

The generic -isystem <prefix>/include and -L <prefix>/lib entries go:
those directories hold nothing for the target, and the driver already
searches <prefix>/m68k-amigaos/include and lib. Translated to find-file
they resolved from the runtime's -B directory instead and put
m68k-amigaos/lib in front of clib2/lib, so -mcrt=clib2 linked the wrong
libc.a.
@codewiz codewiz added ci-amigaos Build the AmigaOS-hosted toolchain ci-linux Build the Linux toolchain (plus the fast amigaos.exp testsuite) labels Sep 8, 2026
@codewiz
codewiz requested a balanced review from Copilot September 9, 2026 01:14

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.

🟡 Changes recommended

The removed prefix helper is still referenced by the AmigaOS C++ driver, and libiberty’s fallback uses the wrong path separator.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Relocates AmigaOS-hosted GCC resources relative to the executable instead of relying on GCC:.

Changes:

  • Resolves bare executable names through PROGDIR:.
  • Uses semicolon-separated host paths and restores environment-based linker lookup.
  • Replaces sdk_root specs with %:find-file.
File summaries
File Description
libiberty/pex-amigaos.c Updates environment inheritance documentation.
libiberty/make-relative-prefix.c Restores generic relocation logic with AmigaOS resolution.
gcc/gcc.cc Removes the AmigaOS prefix helper.
gcc/config/m68k/xm-amigaos.h Defines the host path separator.
gcc/config/m68k/m68kamigaos.h Migrates SDK paths to %:find-file.
gcc/config.host Registers the AmigaOS host configuration.
gcc/collect2.cc Restores environment-based linker search paths.
Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 2
  • Review effort level: Balanced

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

Comment thread gcc/gcc.cc
Comment thread libiberty/make-relative-prefix.c
@codewiz codewiz added ci-amigaos Build the AmigaOS-hosted toolchain and removed ci-amigaos Build the AmigaOS-hosted toolchain labels Sep 9, 2026
make-relative-prefix.c picks its own PATH_SEPARATOR, so the PATH walk
that runs when PROGDIR: cannot be resolved split AmigaDOS path lists
inside the volume names.
TARGET_AMIGAOS comes from amigaos-protos.h through tm_p.h, which the
driver never includes, so this block was never compiled. It called the
sdk_root helper that no longer exists, and the __init_eh reference it
wanted to add is already in LINK_SPEC.
@codewiz codewiz added ci-linux Build the Linux toolchain (plus the fast amigaos.exp testsuite) ci-amigaos Build the AmigaOS-hosted toolchain and removed ci-linux Build the Linux toolchain (plus the fast amigaos.exp testsuite) ci-amigaos Build the AmigaOS-hosted toolchain labels Sep 9, 2026
@codewiz
codewiz requested a balanced review from Copilot September 9, 2026 02:27
@codewiz
codewiz requested review from MBeijer and reinauer September 9, 2026 02:27

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.

🟡 Changes recommended

Executables located at an Amiga volume root lose their volume prefix during relative-prefix calculation.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 8/8 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment on lines +92 to +94
#elif defined (__amiga__)
/* A colon ends an AmigaDOS volume or assign name. */
# define PATH_SEPARATOR ';'

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not changing this. An executable directly in a volume root has no prefix to derive: the prefix is the parent of bin/, and a volume root has no parent on AmigaDOS. The installed layout is always /bin/, and that case works: gcc:bin/m68k-amigaos-gcc yields gcc:bin/../lib/... and gcc:bin/../libexec/.... Treating the colon as a directory separator would break it, since the components are rejoined with a slash and SDK:/bin means the parent of the root on AmigaDOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-amigaos Build the AmigaOS-hosted toolchain ci-linux Build the Linux toolchain (plus the fast amigaos.exp testsuite)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants