[libatomic] : fix building inside the source directory [PR125583]

Message ID VI0PR08MB10392C18BB4E240C544C8ED23FF132@VI0PR08MB10392.eurprd08.prod.outlook.com
State New
Headers
Series [libatomic] : fix building inside the source directory [PR125583] |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_simplebootstrap_build--master-aarch64-bootstrap success Build passed
linaro-tcwg-bot/tcwg_simplebootstrap_build--master-arm-bootstrap success Build passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Test passed

Commit Message

Tamar Christina June 3, 2026, 1:28 p.m. UTC
  Since the libatomic_asneeded libtool workarounds GCC no longer builds if
./configure is ran inside the source tree.

it fails at building libgomp with

checking whether the C compiler works... no
configure: error: in `/root/gcc-16.1.0/aarch64-unknown-linux-gnu/libgomp':
configure: error: C compiler cannot create executables
See `config.log' for more details
make[2]: *** [Makefile:23007: configure-stage1-target-libgomp] Error 77

This happens because in configure.ac there is

# --srcdir=. covers the toplevel, while "test -d" covers the subdirectories
if ( test $srcdir = . && test -d gcc ) \
   || test -d $srcdir/../host-${host_noncanonical}; then
  host_subdir="host-${host_noncanonical}"
else
  host_subdir=.
fi
# No prefix.
target_subdir=${target_noncanonical}

which shifts `host_subdir` to `host-${host_noncanonical}`

however the chunks in libatomic assumes that the `host_subdir` is `.` leading to
the builds not working.

This fixes it by passing HOST_SUBDIR down to child Makefiles and then using it
in libatomic.  It defaults to . in libatomic if not provided to support
standalone builds.

Bootstrapped Regtested on aarch64-none-linux-gnu,
arm-none-linux-gnueabihf, x86_64-pc-linux-gnu
-m32, -m64 and no issues.

Also tested an in source folder build and that works now too.

Ok for master? and backport to GCC 16 after some stew?

Thanks,
Tamar

ChangeLog:

	PR bootstrap/125583
	* Makefile.in: Pass HOST_SUBDIR down.
	* Makefile.tpl: likewise.

libatomic/ChangeLog:

	PR bootstrap/125583
	* Makefile.am: Use HOST_SUBDIR in gcc_objdir.
	* Makefile.in: Likewise.

---


--
  

Patch

diff --git a/Makefile.in b/Makefile.in
index f34142cc077dd9f647398b6185f2761361d16b75..15d1897a78240112ac56faa59ac5936b7759970c 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -1111,6 +1111,7 @@  EXTRA_TARGET_FLAGS = \
 	'GM2FLAGS=$$(GM2FLAGS_FOR_TARGET)' \
 	'LD=$(COMPILER_LD_FOR_TARGET)' \
 	'LDFLAGS=$$(LDFLAGS_FOR_TARGET)' \
+	'HOST_SUBDIR=$(HOST_SUBDIR)' \
 	'LIBCFLAGS=$$(LIBCFLAGS_FOR_TARGET)' \
 	'LIBCXXFLAGS=$$(LIBCXXFLAGS_FOR_TARGET)' \
 	'NM=$(COMPILER_NM_FOR_TARGET)' \
diff --git a/Makefile.tpl b/Makefile.tpl
index 5891b67b69749f6c122fcc0e851cc244fb655adc..af4a5d0c1951640581b1e450db642e5cd99cd440 100644
--- a/Makefile.tpl
+++ b/Makefile.tpl
@@ -836,6 +836,7 @@  EXTRA_TARGET_FLAGS = \
 	'GM2FLAGS=$$(GM2FLAGS_FOR_TARGET)' \
 	'LD=$(COMPILER_LD_FOR_TARGET)' \
 	'LDFLAGS=$$(LDFLAGS_FOR_TARGET)' \
+	'HOST_SUBDIR=$(HOST_SUBDIR)' \
 	'LIBCFLAGS=$$(LIBCFLAGS_FOR_TARGET)' \
 	'LIBCXXFLAGS=$$(LIBCXXFLAGS_FOR_TARGET)' \
 	'NM=$(COMPILER_NM_FOR_TARGET)' \
diff --git a/libatomic/Makefile.am b/libatomic/Makefile.am
index 49689d4510180eecb9b193de5db7ea5e8cffc139..8fb7390bcf187b29a89dc1ff97d2699be9d737ea 100644
--- a/libatomic/Makefile.am
+++ b/libatomic/Makefile.am
@@ -180,7 +180,8 @@  all-multi: $(libatomic_la_LIBADD)
 # built after libatomic, which makes RPATH insecure. Removing libatomic.la
 # from $gcc_objdir seems to fix the issue.
 
-gcc_objdir = `pwd`/$(MULTIBUILDTOP)../../gcc/
+HOST_SUBDIR = .
+gcc_objdir = `pwd`/$(MULTIBUILDTOP)../../$(HOST_SUBDIR)/gcc/
 all-local: stmp-libatomic
 stmp-libatomic: libatomic.la
 	$(LIBTOOL) --mode=install $(INSTALL_DATA) libatomic.la $(gcc_objdir)$(MULTISUBDIR)/
diff --git a/libatomic/Makefile.in b/libatomic/Makefile.in
index e7f12134ac5927116c1865437b6a3ca1631c839a..e315bfb288f68727a21e8966393190836e56fa54 100644
--- a/libatomic/Makefile.in
+++ b/libatomic/Makefile.in
@@ -486,7 +486,8 @@  libatomic_convenience_la_LIBADD = $(libatomic_la_LIBADD)
 # which (somehow) ends up adding $gcc_objdir to RPATH for libraries that get
 # built after libatomic, which makes RPATH insecure. Removing libatomic.la
 # from $gcc_objdir seems to fix the issue.
-gcc_objdir = `pwd`/$(MULTIBUILDTOP)../../gcc/
+HOST_SUBDIR = .
+gcc_objdir = `pwd`/$(MULTIBUILDTOP)../../$(HOST_SUBDIR)/gcc/
 MULTISRCTOP = 
 MULTIBUILDTOP = 
 MULTIDIRS =