Bug 12327 - x86 relocatable kernel is broken
Summary: x86 relocatable kernel is broken
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.22
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL: http://sourceware.org/ml/binutils/201...
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-16 04:21 UTC by H.J. Lu
Modified: 2014-05-28 19:42 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2010-12-16 04:21:54 UTC
In linux kernel, we have ‘jiffies = jiffies_64;’ in vmlinux.lds.S.
The jiffies isn’t in any section. In kernel build, there is warning saying jiffies is an absolute address and can't relocatable. In my system, this cause boot panic. 

Kernel config has

CONFIG_RELOCATABLE=y

Kernel build log has

WARNING: Absolute relocations present
Offset     Info     Type     Sym.Value Sym.Name
c102cc8a 00de5a01   R_386_32 c170ba40  jiffies
c103635d 00de5a01   R_386_32 c170ba40  jiffies
c1036658 00de5a01   R_386_32 c170ba40  jiffies

Linker command is

ld -m elf_i386 --emit-relocs --build-id -o vmlinux -T arch/x86/kernel/vmlinux.lds arch/x86/kernel/head_32.o arch/x86/kernel/head32.o arch/x86/kernel/head.o arch/x86/kernel/init_task.o  init/built-in.o --start-group  usr/built-in.o  arch/x86/built-in.o  kernel/built-in.o  mm/built-in.o  fs/built-in.o  ipc/built-in.o  security/built-in.o  crypto/built-in.o  block/built-in.o  lib/lib.a  arch/x86/lib/lib.a  lib/built-in.o  arch/x86/lib/built-in.o  drivers/built-in.o  sound/built-in.o  firmware/built-in.o  arch/x86/pci/built-in.o  arch/x86/oprofile/built-in.o  arch/x86/power/built-in.o  arch/x86/video/built-in.o  net/built-in.o --end-group .tmp_kallsyms2.o

arch/x86/kernel/vmlinux.lds has

OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
OUTPUT_ARCH(i386)
ENTRY(phys_startup_32)
jiffies = jiffies_64;
PHDRS {
 text PT_LOAD FLAGS(5); /* R_E */
 data PT_LOAD FLAGS(7); /* RWE */
 note PT_NOTE FLAGS(0); /* ___ */
}
Comment 1 H.J. Lu 2010-12-16 04:26:19 UTC
It is caused by

http://sourceware.org/ml/binutils/2010-08/msg00169.html
Comment 2 Andreas Schwab 2010-12-16 17:26:44 UTC
The obvious fix is to move the symbol in a section.
Comment 3 H.J. Lu 2010-12-16 22:04:15 UTC
A patch is posted at

http://sourceware.org/ml/binutils/2010-12/msg00513.html
Comment 4 H.J. Lu 2010-12-17 00:07:47 UTC
The updated patch is posted at

http://sourceware.org/ml/binutils/2010-12/msg00520.html
Comment 5 H.J. Lu 2010-12-17 00:08:43 UTC
Another testcase from:

http://sourceware.org/ml/binutils/2010-12/msg00519.html

--
> Your patch doesn't work. I got
> 
> ./ld: kernel image bigger than KERNEL_IMAGE_SIZE
> 
> due to arch/x86/kernel/vmlinux.lds:
> 
> ----
> /*
>  * Build-time check on the image size:
>  */
> . = ASSERT((_end - _text <= (512 * 1024 * 1024)),
>     "kernel image bigger than KERNEL_IMAGE_SIZE");

Extracting the relevant parts from the kernel link script:

SECTIONS
{
  . = 0xc000;
  .text :
  {
    _text = .;
    *(.text)
  }
  _end = .;
}
ASSERT (_end - _text <= 0x100, "fail");

You'd think that under the new rules, this ought to work.  "_end" is
an absolute address, so when evaluating "_end - _text", "_text" ought
to be converted from relative to absolute, the subtraction resuling in
an absolute address.  Then 0x100 gets converted from a number to
absolute address before being compared.

The trouble is that "_end" is *not* treated as an absolute address but
as a plain number.  That makes ld convert "_end" to a .text relative
address when evaluation "_end - _text", which doesn't cause a problem
at that stage, but the result is a relative address.  That means 0x100
is converted to a .text relative address too, which gives the wrong
result.

The underlying problem is that we don't distinguish between plain
numbers and absolute addresses once values are stored in symbols.
--
Comment 6 Sourceware Commits 2010-12-28 18:04:14 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	hjl@sourceware.org	2010-12-28 18:04:10

Modified files:
	ld/testsuite   : ChangeLog 
	ld/testsuite/ld-scripts: defined.exp expr.exp 
Added files:
	ld/testsuite/ld-scripts: defined4.d defined4.s defined4.t 
	                         expr2.d expr2.s expr2.t 

Log message:
	Add testcases for PR ld/12327.
	
	2010-12-28  H.J. Lu  <hongjiu.lu@intel.com>
	
	PR ld/12327
	* ld-scripts/defined4.d: New.
	* ld-scripts/defined4.s: Likewise.
	* ld-scripts/defined4.t: Likewise.
	* ld-scripts/expr2.d: Likewise.
	* ld-scripts/expr2.s: Likewise.
	* ld-scripts/expr2.t: Likewise.
	
	* ld-scripts/defined.exp: Run defined4.
	
	* ld-scripts/expr.exp: Run expr2.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1341&r2=1.1342
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-scripts/defined4.d.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-scripts/defined4.s.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-scripts/defined4.t.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-scripts/expr2.d.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-scripts/expr2.s.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-scripts/expr2.t.diff?cvsroot=src&r1=NONE&r2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-scripts/defined.exp.diff?cvsroot=src&r1=1.11&r2=1.12
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-scripts/expr.exp.diff?cvsroot=src&r1=1.2&r2=1.3
Comment 8 Sourceware Commits 2010-12-29 01:03:36 UTC
CVSROOT:	/cvs/src
Module name:	src
Changes by:	hjl@sourceware.org	2010-12-29 01:03:32

Modified files:
	ld             : ChangeLog 

Log message:
	Mention PR ld/12327 in ChangeLog entry.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ChangeLog.diff?cvsroot=src&r1=1.2258&r2=1.2259
Comment 9 Sourceware Commits 2011-02-01 21:20:54 UTC
CVSROOT:	/cvs/src
Module name:	src
Branch: 	binutils-2_21-branch
Changes by:	amodra@sourceware.org	2011-02-01 21:20:51

Modified files:
	ld             : ChangeLog 

Log message:
	Mention PR ld/12327 in ChangeLog entry.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_21-branch&r1=1.2222.2.11&r2=1.2222.2.12
Comment 10 Jackie Rosen 2014-02-16 18:23:56 UTC Comment hidden (spam)