0

I'm installing gcc 4.6.1 on OS X for MIT xv6:

tar xjf gcc-core-4.6.1.tar.bz2
cd gcc-4.6.1
mkdir build
cd build
../configure --prefix=/usr/local \
    --target=i386-jos-elf --disable-werror \
    --disable-libssp --disable-libmudflap --with-newlib \
    --without-headers --enable-languages=c

Things are good until make all-gcc:

gtype-desc.c:8838:18: error: subscripted value is not an array,
      pointer, or vector
    sizeof (x_rtl[0]),
            ~~~~~^~
gtype-desc.c:8957:36: error: subscripted value is not an array,
      pointer, or vector
    sizeof (default_target_libfuncs[0]),
            ~~~~~~~~~~~~~~~~~~~~~~~^~
gtype-desc.c:9041:31: error: subscripted value is not an array,
      pointer, or vector
    sizeof (default_target_rtl[0]),
            ~~~~~~~~~~~~~~~~~~^~
gtype-desc.c:9062:31: error: subscripted value is not an array,
      pointer, or vector
    sizeof (default_target_rtl[0]),
            ~~~~~~~~~~~~~~~~~~^~
gtype-desc.c:9069:31: error: subscripted value is not an array,
      pointer, or vector
    sizeof (default_target_rtl[0]),
            ~~~~~~~~~~~~~~~~~~^~
gtype-desc.c:9076:31: error: subscripted value is not an array,
      pointer, or vector
    sizeof (default_target_rtl[0]),
            ~~~~~~~~~~~~~~~~~~^~
68 warnings and 6 errors generated.
make[1]: *** [gtype-desc.o] Error 1
make: *** [all-gcc] Error 2

There are also errors in make install-gcc, make all-target-libgcc and make install-target-libgcc and i386-jos-elf-gcc -v show command not found.

What should I do to fix this? Is there an alternative to use command i386-jos-elf-gcc?

gcc --version

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1

Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)

Target: x86_64-apple-darwin15.3.0

Thread model: posix

>

>

which gcc

/usr/bin/gcc

It seems that I do have a gcc compiler, but which has been redirected to clang?

Rahn
  • 4,787
  • 4
  • 31
  • 57
  • I recently built gcc-4.6.3 under OS X 10.9.5 and it *almost* worked right out of the box. What compiler is stage 1 of the gcc build running on? Xcode? The impression I get is that gcc 4.6 is a bit too old for XCode; I had to make a few tweaks to get it to work. (Although the errors I had were different from the ones you're showing.) – Steve Summit Mar 03 '16 at 17:56
  • One thing I did differently that you is that I gave fewer options to `configure`, basically just `--prefix=/usr/local/gcc` (since that's where I'm installing it). I don't think you need those other options, unless you're trying to build a cross-compiler. (Are you trying to build a cross-compiler?) – Steve Summit Mar 03 '16 at 17:58
  • Also, the gcc build instructions say you should *not* have your build directory inside the unpacked source directory. (And I get the impression this is more than just a theoretical concern.) I recommend eliminating the `cd gcc-4.6.1` step from your recipe, and changing `../configure` to `../gcc-4.6.1/configure`. – Steve Summit Mar 03 '16 at 18:02
  • @SteveSummit I do think the option is necessary such as `--target=i386-jos-elf`. I'm working toward `i386-jos-elf-gcc`. – Rahn Mar 04 '16 at 00:35
  • @SteveSummit I'm trying on building to build a cross-compiler. check [the link](https://doesnotscale.com/compiling-xv6-on-os-x-10-9/): `The most difficult part of this process was figuring out how to compile gcc into an ELF cross compiler`. But, I don't know why I have to do all of this... – Rahn Mar 04 '16 at 00:37
  • @SteveSummit Does it has anything to do with the (gcc to clang) redirection? (check my new edit) – Rahn Mar 04 '16 at 00:45
  • See [Building GCC on OS X 10.11](https://stackoverflow.com/questions/33860902/building-gcc-on-os-x-10-11/33930736#33930736) for a description of what I did with GCC 5.2.0 (and 5.3.0), and that in turn links to [Install GNU GCC on Mac](https://stackoverflow.com/questions/21173518/install-gnu-gcc-on-mac/21213759#21213759), which discusses installing GCC 4.8.2 on Mac OS X 10.9. The stories are similar. I've not tried building older GCC on Mac OS X 10.11 (yet) — I used to have older versions from when I built them, but El Capitan made them obsolete because I can no longer create `/usr/gcc`. – Jonathan Leffler Mar 04 '16 at 01:05
  • @Rahn: My situation is a little different from yours: I'm building an arm cross-compiler, using a slightly different version of gcc, on a slightly different version of MacOS. So I can't be sure your problems are similar enough to mine that my suggestions will make any difference for you. But to keep all the suggestions in one place, if you don't mind, I'm going to add them over at http://stackoverflow.com/questions/33860902/building-gcc-on-os-x-10-11 . – Steve Summit Mar 04 '16 at 09:15
  • You said, "It seems that I do have a gcc compiler, but which has been redirected to clang". What you have is clang (aka Xcode), masquerading as gcc. Evidently there are so many packages whose Makefiles reference gcc that when you install Xcode, it creates `/usr/bin/gcc` and `/usr/bin/g++` which are actually just clang invocations. One of the things I did when I bootstrapped a native gcc for my Mac was to remove these entries from /usr/bin. – Steve Summit Mar 04 '16 at 09:18
  • @JonathanLeffler So, is it all about the bootstrap compiler in building `gcc`? – Rahn Mar 04 '16 at 11:51
  • @Rahn: The bootstrap compiler is very important. AFAICR, I have not successfully built GCC starting with a previous home-built version, which continues to surprise me. I've not experimented with versions of GCC built by packagers (brew, Mac ports, etc). I've also not gone experimenting with deep paths like you're using. I've had the command line tools installed with the compilers in `/usr/bin` and the headers in `/usr/include`, etc. – Jonathan Leffler Mar 04 '16 at 14:30
  • @JonathanLeffler I don't know why the package managers not recommended. Or because `gcc` is involved lots of (system) stuff? – Rahn Mar 04 '16 at 15:04
  • @Rahn: if you read carefully, I didn't say that the versions from packagers are 'not recommended'; I simply said I've not experimented with using them as bootstrap compilers. That's a passive 'absence of recommendation' (based on absence of knowledge because I've not tried it) rather than an active 'not recommended'. I also have not experimented with GNU `binutils`. My goal is mainly a working GCC rather than understanding all the possible ways in which it could be built. – Jonathan Leffler Mar 04 '16 at 15:11
  • I've just checked my script for building GCC 5.3.0 on El Capitan; it explicitly sets the bootstrap compilers to `clang` and `clang++`. – Jonathan Leffler Mar 04 '16 at 15:15
  • I just tried building GCC 4.6.3 using the basic script I used for 5.3.0. The first attempt using `make -j8` failed because one bootstrap step couldn't find GMP. The second attempt without the `-j8` failed after building MPFR while trying to configure MPC, but it failed because it couldn't find MPFR — which is kinda frustrating. It might work OK with MPFR installed somewhere that the compiler is looking anyway (`/usr/local/lib` etc, for example). I may or may not work up the energy to experiment with installing GMP, MPFR, MPC under `/usr/local`. – Jonathan Leffler Mar 04 '16 at 15:38
  • I did build GMP 6.0.0, MPFR 3.1.3, MPC 1.0.3 and install them in `/usr/local`, and then tried to rebuild GCC 4.6.3 using those. It got a fair way, but there was a crash using the stage 1 compiler, AFAICT — it was not successful. I have no real interest in GCC 4.6.3 so I won't be going further with this experiment. Suffice to say, it is likely to be hard work getting it built successfully. (I have also not checked which versions of GMP, MPFR, MPC were expected by GCC 4.6.3 — I have not read the version's installation instructions. Take my negative story with suitably large pinches of salt.) – Jonathan Leffler Mar 04 '16 at 17:00
  • What's with people installing antique versions of packages? The linked webpage explicitly says: "You may also use newer versions of these packages". – Marc Glisse Sep 23 '16 at 09:24

2 Answers2

0

[This is not a complete answer.]

First, see the answers at Building GCC on OS X 10.11 .

Second: If you're trying to build a cross-compiler, it's highly recommended that you first bootstrap a native version of gcc. See also the section "Building a cross compiler" in INSTALL/build.html . I built mine with --prefix=/usr/local/gcc, so that my native gcc ended up in /usr/local/gcc/bin/gcc . Then I added /usr/local/gcc/bin to my $PATH, and got rid of /usr/bin/gcc and /usr/bin/g++ to be on the safe side.

As build.html points out, you're also going to need a "cross-assembler" and "cross-linker". So you generally need to download an appropriate version of binutils, and build those before trying to build your cross-compiler. (This is the step I, myself, am currently stuck on. I may have more to say about this later.)

Finally, if you discover that your build is failing because you configured it improperly, such that you have to rerun configure with different options, it's safer to delete your entire build directory and start from scratch. The configure and build system sometimes, but it seems not 100% reliably, detects what might need rebuilding in that case. (Deleting and starting over is frustrating, I agree, but again, it can really save time in the long run.)

Steve Summit
  • 45,437
  • 7
  • 70
  • 103
  • So, the key is that I should use `gcc` as bootstrap compiler rather than `clang` when compiling `gcc`? – Rahn Mar 04 '16 at 11:50
  • @Rahn: I don't know about *the* key, but certainly one important factor. It sounds like extra work, but I'm pretty sure it'll save you time and frustration in the long run. – Steve Summit Mar 04 '16 at 12:39
  • 1
    To be very clear: If you start with (a modern version of) MacOS, and install Xcode at all, you've got clang. Now, clang-pretending-to-be-gcc is sufficient for bootstrapping a native copy of the real gcc. But it's recommended that you use that native copy of the real gcc (*not* clang-pretending-to-be-gcc) to build a gcc cross-compiler. – Steve Summit Mar 04 '16 at 14:54
0

I am also installing gcc 4.6.1 for MIT xv6 now, but on Ubuntu. I do not know if you see this:

MAC OS X 10.7 "LION" NOTE: The default clang compiler on Mac OS X 10.7
cannot build a working version of GCC. Use the following configure
line to work around the problem (this has reported to work with OS X 10.9.4 withXCode 5.1.1 and its Command Line Tools package (for gcc):
../configure --prefix=/usr/local \
    --target=i386-jos-elf --disable-werror \
    --disable-libssp --disable-libmudflap --with-newlib \
    --without-headers --enable-languages=c \
    CC=/usr/bin/gcc-4.2 \

I copied it from this page.(But I think it is not necessary for you to use that command, coz you said things are good.) If you still have that problem,this page may give you some tips. On your Mac, use tools or command mdfind to find where the file gengtype.c is, and modify the code that it mentioned on that page. I hope you can solve it.

Simon Hänisch
  • 4,740
  • 2
  • 30
  • 42
A.Flash
  • 71
  • 1