Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 439082 - sys-boot/grub: does not boot when built with gold linker
Summary: sys-boot/grub: does not boot when built with gold linker
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: AMD64 Linux
: Normal normal (vote)
Assignee: Gentoo's Team for Core System packages
URL: http://savannah.gnu.org/bugs/?34539
Whiteboard:
Keywords:
Depends on:
Blocks: systemwide-gold
  Show dependency tree
 
Reported: 2012-10-20 17:15 UTC by Ambroz Bizjak
Modified: 2024-04-04 19:06 UTC (History)
13 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
add check for gold to ebuild (grub-2.00-r1.ebuild-gold-check.patch,683 bytes, patch)
2012-10-20 17:39 UTC, Ambroz Bizjak
Details | Diff
Force ld.bfd via --fuse-ld CFLAG (grub-2.00-r3-gold-workaround.patch,899 bytes, patch)
2013-07-15 06:40 UTC, Cosmin Giradu
Details | Diff
Force ld.bfd via --fuse-ld CFLAG (grub-2.00-r4.ebuild) (file_439082.txt,1016 bytes, patch)
2013-07-24 14:13 UTC, Alex Xu (Hello71)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ambroz Bizjak 2012-10-20 17:15:55 UTC
Grub 2 builds with the Gold linker, but makes the machine unbootable after grub2-setup is run; "GRUB is loading" never shows up and the screen remains blank indefinitely.

Having had to recover my machine a few times because of this, I suggest that we add a check in the ebuild to bail out if the Gold linker is detected.
Comment 1 Ambroz Bizjak 2012-10-20 17:39:32 UTC
Created attachment 327008 [details, diff]
add check for gold to ebuild

This patch adds a check in src_prepare() to die if the Gold linker is detected.
Comment 2 Mike Gilbert gentoo-dev 2012-10-20 21:09:20 UTC
Confirmed in qemu. Looks like there is a bug report upstream that nobody has looked at.
Comment 3 Mike Gilbert gentoo-dev 2012-10-20 21:47:44 UTC
+  20 Oct 2012; Mike Gilbert <floppym@gentoo.org> grub-2.00-r1.ebuild,
+  grub-9999.ebuild:
+  Add pkg_pretend check to bail out if we are using the gold linker. Bug 439082
+  by Ambroz Bizjak.
Comment 4 SpanKY gentoo-dev 2012-10-22 04:35:56 UTC
there should be only one place in grub-2.00-r1 that still needs tweaking

configure.ac:      CFLAGS="$TARGET_CFLAGS -nostdlib ${TARGET_IMG_LDFLAGS_AC} ${TARGET_IMG_BASE_LDOPT},8000 -Wl,--defsym,___main=0x8100"

change the 8000 to 0x8000
Comment 5 Mike Gilbert gentoo-dev 2012-10-22 23:08:15 UTC
(In reply to comment #4)

I gave that a shot, but grub still doesn't load.
Comment 6 Cosmin Giradu 2013-07-15 06:40:43 UTC
Created attachment 353312 [details, diff]
Force ld.bfd via --fuse-ld CFLAG

As stated in BUG#466536 (where I initially added this by mistake):

Would it make more sense to « append-cflags "-fuse-ld=bfd" », instead of complaining about gold usage, until the bug is resolved upstream?
Comment 7 Alex Xu (Hello71) 2013-07-24 14:13:54 UTC
Created attachment 354098 [details, diff]
Force ld.bfd via --fuse-ld CFLAG (grub-2.00-r4.ebuild)

Fixed for grub-2.00-r4.ebuild. Applies cleanly with "-F 9999".
Comment 8 Mike Gilbert gentoo-dev 2013-07-24 14:24:30 UTC
If I am not mistaken, the -fuse-ld option does not work before gcc-4.8.0.
Comment 9 Alex Xu (Hello71) 2013-07-24 15:05:22 UTC
Comment on attachment 354098 [details, diff]
Force ld.bfd via --fuse-ld CFLAG (grub-2.00-r4.ebuild)

Holy... damn.

I just looked at the patch.

I expected patch to actually do something sensible.
Comment 10 Doug Goldstein (RETIRED) gentoo-dev 2013-07-24 18:54:36 UTC
(In reply to Mike Gilbert from comment #8)
> If I am not mistaken, the -fuse-ld option does not work before gcc-4.8.0.

Mike,

Can't you do something similar to what I've done in sys-firmware/sgabios?
Comment 11 Mike Gilbert gentoo-dev 2013-07-24 19:11:41 UTC
(In reply to Doug Goldstein from comment #10)
> Can't you do something similar to what I've done in sys-firmware/sgabios?

I assume you are referring to this:

        emake CC=$(tc-getCC) LD="$(tc-getLD).bfd" AR=$(tc-getAR) \
            OBJCOPY=$(tc-getOBJCOPY)

That would only be effective if grub's build system actually calls $(LD) directly. When the linker is invoked indirectly via the C compiler, ${LD} is ignored. That's the entire reason the "-fuse-ld" gcc option was added.

If you think I'm wrong here, let me know and I will double-check the grub build system to see how it is invoking the linker.
Comment 12 Doug Goldstein (RETIRED) gentoo-dev 2013-07-24 19:19:44 UTC
(In reply to Mike Gilbert from comment #11)
> (In reply to Doug Goldstein from comment #10)
> > Can't you do something similar to what I've done in sys-firmware/sgabios?
> 
> I assume you are referring to this:
> 
>         emake CC=$(tc-getCC) LD="$(tc-getLD).bfd" AR=$(tc-getAR) \
>             OBJCOPY=$(tc-getOBJCOPY)
> 
> That would only be effective if grub's build system actually calls $(LD)
> directly. When the linker is invoked indirectly via the C compiler, ${LD} is
> ignored. That's the entire reason the "-fuse-ld" gcc option was added.
> 
> If you think I'm wrong here, let me know and I will double-check the grub
> build system to see how it is invoking the linker.

I guess I phased it poorly. It wasn't a "hey do this" it was more "would this work". You are correct the grub build system would have to directly call LD, if its invoked via the compiler it wouldn't work.
Comment 13 Mike Gilbert gentoo-dev 2013-07-24 19:34:38 UTC
(In reply to Doug Goldstein from comment #12)

Ah, ok. Well, I just had a quick glance at a build log, it it looks like it is running $(CC) to do the linking.

I guess I could set up a special case if the user has at least gcc-4.8 and is using gold. I'll probably wait until I add a new grub snapshot to do that, which should be pretty soon.
Comment 14 Mike Gilbert gentoo-dev 2013-08-04 20:42:52 UTC
+*grub-2.00_p5086 (04 Aug 2013)
+
+  04 Aug 2013; Mike Gilbert <floppym@gentoo.org> +grub-2.00_p5086.ebuild,
+  grub-9999.ebuild:
+  New snapshot, resolves bug 468136. Append -fuse-ld=bfd to LDFLAGS for gcc-4.8+
+  as a workaround for bug 439082.
Comment 16 Mike Gilbert gentoo-dev 2015-03-17 02:00:54 UTC
+  17 Mar 2015; Mike Gilbert <floppym@gentoo.org> grub-2.00_p5107-r2.ebuild,
+  grub-2.02_beta2-r3.ebuild, grub-2.02_beta2-r6.ebuild,
+  grub-2.02_beta2-r7.ebuild, grub-9999-r1.ebuild:
+  We need to set TARGET_LDFLAGS, not LDFLAGS.
Comment 17 Bernd Buschinski 2017-03-18 10:10:07 UTC
Is this still a problem with grub-2.02_rc* ?
Comment 18 George L. Emigh 2017-12-31 02:20:34 UTC
is this still a problem for the stable sys-boot/grub-2.02
Comment 19 Mike Gilbert gentoo-dev 2017-12-31 02:33:42 UTC
Yes, it is still a problem. Please don't ask again unless you have some evidence to the contrary.
Comment 20 Mike Gilbert gentoo-dev 2024-04-04 19:06:27 UTC
With grub-2.12, I get this error when running grub-install, so definitely still broken.

grub-install: info: grub-mkimage --directory '/usr/lib/grub/i386-pc' --prefix '(,msdos1)/boot/grub' --output '/mnt/gentoo/boot/grub/i386-pc/core.img' --format 'i386-pc' --compression 'auto' 'ext2' 'part_msdos' 'biosdisk'
.
grub-install: info: the total module size is 0x3e44.
grub-install: info: reading /usr/lib/grub/i386-pc/kernel.img.
grub-install: info: locating the section .text at 0x0.
grub-install: error: `/usr/lib/grub/i386-pc/kernel.img' is miscompiled: its start address is 0x9074 instead of 0x9000: ld.gold bug?.