bugGNU GRUB - Bugs: bug #32676, Linker error in...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #32676: Linker error in 'grub-core/kern/i386/pc/startup.S' on a x86_64 system

Submitter:  Alexander Diewald <diewi>
Submitted:  Fri 04 Mar 2011 12:41:25 PM UTC
   
 
Category:  Compilation Severity:  Major
Priority:  5 - Normal Item Group:  Software Error
Status:  Fixed Privacy:  Public
Assigned to:  None Originator Name: 
Open/Closed:  Closed Release:  Bazaar - trunk
Release:  Reproducibility:  Every Time
Planned Release:  None

Jump to the original submission

Wed 06 Apr 2011 02:55:40 PM UTC, comment #9: 

Now It works. Thank you Vladimir, you were a great help. And thanks for the short descriptions of the build process. Very interesting.

Well, my problem was that my system didn't boot when I applied my offset fix (added 0x8) AND changed the compiler flag to Os my system didn't boot. So, I concluded that this doesn't make any difference. Wrong thought. I just tried it again with the Os flag and Vladimirs offset patch and it did work!

I have to say that I didn't work thoroughly enough. Again a lesson for me :)

I will fill a bug report on gentoo.org, so it'll get fixed in the official ebuild soon too.

Alexander Diewald <diewi>
Wed 06 Apr 2011 02:21:09 PM UTC, comment #8: 


> Just tested the patch. It is NOT working. It fixes the
> compilation issue, but after a "grub-install --no-floppy
> /dev/sda" my system just goes on to the message "Grub
> Loading..." and then reboots. So I'm caught in a reboot loop,
> only installing the 1.98 version makes my system behave normal
> again.

Have you checked that your grub-mkimage is updated? It changes depending on offsets. If it did I'll try to recreate it on my FreeBSD

> Also I think that the gcc version isn't causing the error (I'm
> using 4.4.5, see emerge.info). These are assembler files for
> which only gas is called.

These asm files are generated from C files. We needed a highly unusual way of combining files, a way that ld doesn't support. Simplifying this system by logically dividing the files and using ld is post-2.0 objective

> The reason, I think, lies in the different size of "long int" > variables on 32- and 64-bit systems. On a 32-bit system a long > has a size of 4 Bytes, just like an "normal" int, on 64-bit
> systems a long is 8 Bytes large. So, the code will grow too
> large. This would explain why these errors appear only on a
> 64-bit systems.

These files are always compiled and assembled with -m32. Moreover my main system is amd64. No problems here.

>Just BTW, Vladimir, I'd advice you to read more carefully, you
> could have seen that the O2 flag wasn't active by regarding
> the compiler command

We use -Os.

> and I already wrote that I changed the offsets, but it didn't
> boot (my first post). Please don't regard this as any kind of
> offence.

None taken.

Vladimir Serbinenko <phcoder>
Group administrator
Wed 06 Apr 2011 02:01:02 PM UTC, comment #7: 

Just tested the patch. It is NOT working. It fixes the compilation issue, but after a "grub-install --no-floppy /dev/sda" my system just goes on to the message "Grub Loading..." and then reboots. So I'm caught in a reboot loop, only installing the 1.98 version makes my system behave normal again.
I guess Andrey just compiled it, but didn't install it to the MBR.

Also I think that the gcc version isn't causing the error (I'm using 4.4.5, see emerge.info). These are assembler files for which only gas is called.
The reason, I think, lies in the different size of "long int" variables on 32- and 64-bit systems. On a 32-bit system a long has a size of 4 Bytes, just like an "normal" int, on 64-bit systems a long is 8 Bytes large. So, the code will grow too large. This would explain why these errors appear only on a 64-bit systems.
For reason of compatibility one should only use "normal" int(s) as it is 4 Byte large on both system types.
I will have a look into that later on.

Just BTW, Vladimir, I'd advice you to read more carefully, you could have seen that the O2 flag wasn't active by regarding the compiler command and I already wrote that I changed the offsets, but it didn't boot (my first post). Please don't regard this as any kind of offence. I appreciate your work here and that you're doing all this in your free-time. It's just something I'm doing myself often and causes me doing work multiple times unnecessarily.

Alexander Diewald <diewi>
Wed 06 Apr 2011 12:27:36 PM UTC, comment #6: 

Committed  with a comment and adjustments.

Vladimir Serbinenko <phcoder>
Group administrator
Tue 05 Apr 2011 07:28:48 PM UTC, comment #5: 

Hi, Vladimir,

I can confirm: suggested patch fixes compilation issue over here.
Thanks!

PS:
to make it compile smoothly on my system I do still need one more patch (please, see attached file)

(file #23113)

Andrey <devel>
Mon 04 Apr 2011 09:39:22 PM UTC, comment #4: 

Looks like you both use an old compiler which optimizes the code far less than I supposed. Could you try attached patch?

(file #23106)

Vladimir Serbinenko <phcoder>
Group administrator
Tue 08 Mar 2011 06:47:14 PM UTC, comment #3: 

Hi,
the same is over here (tried both: trunk and 1.99rc1)

system: FreeBSD 9-Current [amd64]
compiler: gcc version 4.2.1 20070719

gcc -Wall -W -I../include -I../include  -DGRUB_MACHINE_PCBIOS=1 -DGRUB_MACHINE=I386_PC -Os -Wall -W -Wshadow -Wpointer-arith -Wmissing-prototypes -Wundef -Wstrict-prototypes -g -falign-jumps=1 -falign-loops=1 -falign-functions=1 -mno-mmx -mno-sse -mno-sse2 -mno-3dnow -m32 -fno-stack-protector -mno-stack-arg-probe -Werror  -Os -I.. -S -DSTANDALONE -o rs_decoder.S lib/reed_solomon.c -g0 -mregparm=3
gcc -DHAVE_CONFIG_H -I. -I..  -Wall -W -I../include -I../include  -DGRUB_MACHINE_PCBIOS=1 -DGRUB_MACHINE=I386_PC -DGRUB_FILE=\"kern/i386/pc/startup.S\" -I. -I. -I.. -I.. -I../include -I../include     -g -m32 -DASM_FILE=1     -MT kern/i386/pc/kernel_exec-startup.o -MD -MP -MF kern/i386/pc/.deps-core/kernel_exec-startup.Tpo -c -o kern/i386/pc/kernel_exec-startup.o `test -f 'kern/i386/pc/startup.S' || echo './'`kern/i386/pc/startup.S
reed_solomon.c: Assembler messages:
reed_solomon.c:705: Warning: ignoring changed section attributes for .text
kern/i386/pc/startup.S:161: Error: attempt to move .org backwards
kern/i386/pc/startup.S:456: Error: attempt to move .org backwards
kern/i386/pc/startup.S:458: Error: attempt to move .org backwards
gmake[3]: * [kern/i386/pc/kernel_exec-startup.o] Ошибка 1
gmake[3]: Leaving directory `/tmp/grub/grub-core'
gmake[2]: * [all] Ошибка 2
gmake[2]: Leaving directory `/tmp/grub/grub-core'
gmake[1]: * [all-recursive] Ошибка 1
gmake[1]: Leaving directory `/tmp/grub'
gmake: * [all] Ошибка 2

to make it actually compile on my system I had to revert all changes on startup.S starting from -r2859 (inclusive), i.e. I did it like this:

# bzr export /tmp/grub
# bzr diff -r2785 grub-core/kern/i386/pc/startup.S | ( cd /tmp/grub ; patch -u -R ; )


PS:
btw, there was one more compilation issue I faced to (though I guess it is rather "peculiarity" of compiler and thus didn't file a PR).

It looked like this:
gcc -DHAVE_CONFIG_H -I. -I..  -Wall -W -I../include -I../include  -DGRUB_MACHINE_PCBIOS=1 -DGRUB_MACHINE=I386_PC -DGRUB_FILE=\"video/fb/video_fb.c\" -I. -I. -I.. -I.. -I../include -I../include     -Os -Wall -W -Wshadow -Wpointer-arith -Wmissing-prototypes -Wundef -Wstrict-prototypes -g -falign-jumps=1 -falign-loops=1 -falign-functions=1 -mno-mmx -mno-sse -mno-sse2 -mno-3dnow -m32 -fno-stack-protector -mno-stack-arg-probe -Werror   -mrtd -mregparm=3       -ffreestanding   -MT video/fb/video_fb_module-video_fb.o -MD -MP -MF video/fb/.deps-core/video_fb_module-video_fb.Tpo -c -o video/fb/video_fb_module-video_fb.o `test -f 'video/fb/video_fb.c' || echo './'`video/fb/video_fb.c
cc1: warnings being treated as errors
video/fb/video_fb.c: In function 'grub_video_fb_setup':
video/fb/video_fb.c:1451: warning: passing argument 4 of 'grub_video_fb_doublebuf_blit_init' discards qualifiers from pointer target type
gmake[3]: * [video/fb/video_fb_module-video_fb.o] Ошибка 1
gmake[3]: Leaving directory `/tmp/grub/grub-core'
gmake[2]: * [all] Ошибка 2
gmake[2]: Leaving directory `/tmp/grub/grub-core'
gmake[1]: * [all-recursive] Ошибка 1
gmake[1]: Leaving directory `/tmp/grub'
gmake: * [all] Ошибка 2

I managed to combat the issue in the following way:
--- grub-core/video/fb/video_fb.c.orig  2011-03-08 20:23:25.000000000 +0200
+++ grub-core/video/fb/video_fb.c       2011-03-08 20:24:03.000000000 +0200
@@ -1448,10 +1448,11 @@
       mode_info->mode_type |= (GRUB_VIDEO_MODE_TYPE_DOUBLE_BUFFERED
                               | GRUB_VIDEO_MODE_TYPE_UPDATING_SWAP);
 
+      void pg0ptr = (void ) page0_ptr;
       err = grub_video_fb_doublebuf_blit_init (&framebuffer.front_target,
                                               &framebuffer.back_target,
                                               *mode_info,
-                                              (void *) page0_ptr);
+                                              pg0ptr);
 
       if (!err)
        {

Andrey <devel>
Fri 04 Mar 2011 03:23:20 PM UTC, comment #2: 

Thanks for your reply.

Sorry, I forgot to mention that I negated the UseFlag "custom-cflags" for the grub compilation. This way the option Os is used.

I just set the option Os globally in my /etc/make.conf, cleaned my source directory and compiled again. I'm still getting the same error.

Alexander Diewald <diewi>
Fri 04 Mar 2011 01:02:09 PM UTC, comment #1: 

Please don't override the -Os with -O2

Vladimir Serbinenko <phcoder>
Group administrator
Fri 04 Mar 2011 12:41:25 PM UTC, original submission:  

Hello,

I'm getting the following error when compiling GRUB2 either from the trunk repository or the version "1.99_rc1":
kern/i386/pc/startup.S: Assembler messages:
kern/i386/pc/startup.S:161: Error: attempt to move .org backwards
kern/i386/pc/startup.S:456: Error: attempt to move .org backwards
kern/i386/pc/startup.S:458: Error: attempt to move .org backwards

The command causing this error is:
x86_64-pc-linux-gnu-gcc -DHAVE_CONFIG_H -I. -I..  -Wall -W -I../include -I../include  -DGRUB_MACHINE_PCBIOS=1 -DGRUB_MACHINE=I386_PC -nostdinc -isystem /usr/lib/gcc/x86_64-pc-linux-gnu/4.4.5/include -DGRUB_FILE=\"kern/i386/pc/startup.S\" -I. -I. -I.. -I.. -I../include -I../include     -g -m32 -DASM_FILE=1     -MT kern/i386/pc/kernel_exec-startup.o -MD -MP -MF kern/i386/pc/.deps-core/kernel_exec-startup.Tpo -c -o kern/i386/pc/kernel_exec-startup.o `test -f 'kern/i386/pc/startup.S' || echo './'`kern/i386/pc/startup.S

Here are the lines of code:
(157-161) #include <rs_decoder.S>

    .text

    . = _start + GRUB_KERNEL_I386_PC_NO_REED_SOLOMON_PART

(448-459)  #ifdef ENABLE_LZMA
           #include "lzma_decode.S"
           #endif

           /*
            * The code beyond this point is compressed.  Assert that the uncompressed
            * code fits GRUB_KERNEL_MACHINE_RAW_SIZE.
            */
    . = _start + GRUB_KERNEL_MACHINE_RAW_SIZE

    . = _start + GRUB_KERNEL_MACHINE_PREFIX
VARIABLE(grub_prefix)


According to the documentation of ld (http://sourceware.org/binutils/docs-2.21/ld/Location-Counter.html#Location-Counter) this error is thrown if the allocated space isn't enough for thoe code to fit in. I could fix this error by adding 0x8 at the end of the lines, but then my system didn't boot (obviously).

My system:
I'm running a Gentoo amd64 hardened system. I already switched my gcc and binutils for the vanilla version (glibc was still hardened) but the error remained the same. For testing I also reduced my CFLAGS to "-O2", but it didn't help either. BTW, I disabled ccache for grub compilation.

I added the output of emerge --info to this report.

Regards, Alex

Alexander Diewald <diewi>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #23113:  video_fb.c.patch added by devel (556B - application/octet-stream)
file #23106:  offset.diff added by phcoder (599B - text/x-diff)
file #22836:  emerge-info.txt added by diewi (5KiB - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by devel (Posted a comment)
  • -email is unavailable- added by phcoder (Posted a comment)
  • -email is unavailable- added by diewi (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 5 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2011-04-06 phcoder StatusNone Fixed
        Open/ClosedOpen Closed
    2011-04-05 devel Attached File- Added video_fb.c.patch, #23113
    2011-04-04 phcoder Attached File- Added offset.diff, #23106
    2011-03-04 diewi Attached File- Added emerge-info.txt, #22836

    Back to the top

    Powered by Savane 3.13-d3ae.
    Corresponding source code