https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125232

dragon-archer at outlook dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #64396|0                           |1
        is obsolete|                            |
                 CC|                            |dragon-archer at outlook dot 
com

--- Comment #2 from dragon-archer at outlook dot com ---
Created attachment 64409
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64409&action=edit
Patch to gnattools only

I think I misunderstood the real problem before. The problem I face currently
is that BOOT_LDFLAGS is ignored for gnattools, causing ld's linking failure.
(My BOOT_LDFLAGS contains -B<path to crt2.o>)

`LDFLAGS=` and `LDFLAGS?=` is actually same if `LDFLAGS` is passed as make
arguments or exported in upper level make, and `LDFLAGS = @LDFLAGS@` doesn't
help because it can only add static LDFLAGS gathered from `configure`, without
BOOT_LDFLAGS. 

The real problem is, the generated top-level all-gnattools rule uses
HOST_EXPORTS and STAGE1_FLAGS_TO_PASS unconditionally:

  all-gnattools: configure-gnattools
          @r=`${PWD_COMMAND}`; export r; \
          s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
          $(HOST_EXPORTS)  \
          (cd $(HOST_SUBDIR)/gnattools && \
            $(MAKE) $(BASE_FLAGS_TO_PASS) $(EXTRA_HOST_FLAGS)
$(STAGE1_FLAGS_TO_PASS) \
              $(TARGET-gnattools))

This means that additional linker flags passed as `BOOT_LDFLAGS` in top-level
make is not merged into `LDFLAGS` for gnattools, as the merge process happens
in `POSTSTAGE1_HOST_EXPORTS`:

POSTSTAGE1_HOST_EXPORTS = \ 
    ...
    LDFLAGS="$(POSTSTAGE1_LDFLAGS) $(BOOT_LDFLAGS)"; export LDFLAGS; \
    ...

The attached patch is a small mitigation, which explicitly add $(BOOT_LDFLAGS)
to every use of $(LDFLAGS).

I've also got another patch below which I think fixes the root cause, but may
need more check since it affects not only the Ada part.

---

diff --git a/Makefile.tpl b/Makefile.tpl
index a5ff44e3dbc..f148043b527 100644
--- a/Makefile.tpl
+++ b/Makefile.tpl
@@ -1312,9 +1312,10 @@ all-[+prefix+][+module+]:
configure-[+prefix+][+module+][+ IF bootstrap +][+ ELS
        @: $(MAKE); $(unstage)[+ ENDIF bootstrap +]
        @r=`${PWD_COMMAND}`; export r; \
        s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
-       [+exports+] [+extra_exports+] \
+       [+exports+] [+ IF bootstrap +]$(EXTRA_HOST_EXPORTS)[+ ENDIF bootstrap
+] [+extra_exports+] \
        (cd [+subdir+]/[+module+] && \
          $(MAKE) $(BASE_FLAGS_TO_PASS) [+args+] [+stage1_args+]
[+extra_make_flags+] \
+               [+ IF bootstrap +] $(EXTRA_BOOTSTRAP_FLAGS)[+ ENDIF bootstrap
+] \
                $(TARGET-[+prefix+][+module+]))
 @endif [+prefix+][+module+]

Reply via email to