Opened 4 years ago

Closed 4 years ago

Last modified 11 months ago

#10476 closed bug (fixed)

Wrong ar during cross-compilation

Reported by: jakzale Owned by: thomie
Priority: low Milestone: 7.10.3
Component: Build System (make) Version: 7.11
Keywords: cross-compiling Cc: pho@…
Operating System: MacOS X Architecture: Unknown/Multiple
Type of failure: Building GHC failed Test Case:
Blocked By: Blocking:
Related Tickets: Phab:D1231 Differential Rev(s):
Wiki Page:

Description

It appears that during cross-compilation, while building stage 1 ghc, the build system uses ar for target architecture instead of ar for build/host architecture.

It will cause linking errors on systems where ar for target architecture is incompatible with ar for build/host architecture (sample output attached below).

(...)
"rm" -f libraries/Cabal/Cabal/dist-boot/build/libHSCabal-1.22.3.0-3tdTeip89ooLNDDdwdA54s.a.contents  
"rm" -f libraries/bin-package-db/dist-boot/build/libHSbin-package-db-0.0.0.0-Gk3F1vzzO3g80wuNGtok3x.a libraries/bin-package-db/dist-boot/build/libHSbin-package-db-0.0.0.0-Gk3F1vzzO3g80wuNGtok3x.a.contents  
echo libraries/bin-package-db/dist-boot/build/GHC/PackageDb.o        >> libraries/bin-package-db/dist-boot/build/libHSbin-package-db-0.0.0.0-Gk3F1vzzO3g80wuNGtok3x.a.contents
"/Users/jakub/src/haskell/PNaCl/gsoc/wrappers/i686-unknown-nacl-ar" q  libraries/bin-package-db/dist-boot/build/libHSbin-package-db-0.0.0.0-Gk3F1vzzO3g80wuNGtok3x.a @libraries/bin-package-db/dist-boot/build/libHSbin-package-db-0.0.0.0-Gk3F1vzzO3g80wuNGtok3x.a.contents
/Users/jakub/src/nacl_sdk/pepper_canary/toolchain/mac_x86_newlib/bin/i686-nacl-ar: creating libraries/bin-package-db/dist-boot/build/libHSbin-package-db-0.0.0.0-Gk3F1vzzO3g80wuNGtok3x.a
"rm" -f libraries/bin-package-db/dist-boot/build/libHSbin-package-db-0.0.0.0-Gk3F1vzzO3g80wuNGtok3x.a.contents  
(...)
ld: archive has no table of contents file '/Users/jakub/src/haskell/PNaCl/ghc-pnacl/libraries/terminfo/dist-boot/build/libHSterminfo-0.4.0.1-7qZwBlx3clR8sTBilJl253.a' for architecture x86_64

Change History (13)

comment:1 Changed 4 years ago by rwbarton

Strange, this time it really seems that there is the correct plumbing in place to distinguish the AR commands to be used by different stages, and the variables are substituted correctly in the mk/config.mk of my cross-compiled ghc. Will rerun the build and look for this command in the output later.

comment:2 Changed 4 years ago by rwbarton

Status: newinfoneeded

I confirmed that my cross-compilation uses /usr/bin/ar at this point, so I was unable to reproduce the problem.

What does your bootstrap compiler output for ghc --info under ("ar command",___)? That command should end up as the value of AR_STAGE0 in mk/config.mk, and then get run for ar here since bin-package-db is a stage 0 package.

comment:3 Changed 4 years ago by rwbarton

Operating System: Unknown/MultipleMacOS X

Aaaaaa never mind... from configure.ac:

  if test "x$OS_STAGE0" != "xOSDarwin"; then
    BOOTSTRAPPING_GHC_INFO_FIELD([AR_STAGE0],[ar command])
    BOOTSTRAPPING_GHC_INFO_FIELD([AR_OPTS_STAGE0],[ar flags])
    BOOTSTRAPPING_GHC_INFO_FIELD([ArSupportsAtFile_STAGE0],[ar supports at file])
  else
    AR_STAGE0='$(AR)'
    AR_OPTS_STAGE0='$(AR_OPTS)'
    ArSupportsAtFile_STAGE0='$(ArSupportsAtFile)'
  fi

This certainly explains your problem (since you are on Darwin)...

git blame points to 24746fe78024a1edab843bc710c79c55998ab134. I wonder if it is okay to remove this hack by now?

comment:4 Changed 4 years ago by rwbarton

Status: infoneedednew

comment:5 Changed 4 years ago by jakzale

Removing this hack seems to work for me (ghc-stage1 gets compiled successfully).

comment:6 Changed 4 years ago by jakzale

Owner: set to jakzale

comment:7 Changed 4 years ago by thomie

jakzale: can you submit a patch to Phabricator?

comment:8 Changed 4 years ago by thomie

Owner: changed from jakzale to thomie

Nevermind, I just put a patch up myself.

comment:9 Changed 4 years ago by Thomas Miedema <thomasmiedema@…>

In 864a9c4/ghc:

Build system: remove hack for Mac OSX in configure.ac (#10476)

Cross-compilation on Mac OSX currently doesn't work. While building
stage 1, the build system uses the `ar` for the target architecture
instead of the `ar` for build/host architecture.

The cause is a hack added in 24746fe78024a1edab843bc710c79c55998ab134
(2010), to supporting bootstrap compilers built with older versions of
Xcode. Xcode 4.3 started installing command line tools in a different
location. Assuming this all behind us now, and the paths didn't change
again (you never now), we can delete the hack.

Deleting the hack fixes the cross compilation issue. Tested by Trac user
jakzale.

Reviewed by: austin

Differential Revision: https://phabricator.haskell.org/D1231

comment:10 Changed 4 years ago by thomie

Milestone: 7.10.3
Status: newmerge

comment:11 Changed 4 years ago by bgamari

Resolution: fixed
Status: mergeclosed

Merged to ghc-7.10. Someone speak up before release if we suspect that Xcode 4.3 is still something we need to worry about.

comment:12 Changed 4 years ago by PHO

Cc: pho@… added

comment:13 Changed 11 months ago by bgamari

Component: Build SystemBuild System (make)

The new Hadrian build system has been merged. Relabeling the tickets concerning the legacy make build system to prevent confusion.

Note: See TracTickets for help on using tickets.