LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 12-09-2008, 04:58 PM   #1
tytus
LQ Newbie
 
Registered: Jan 2005
Location: promanus
Distribution: promanus
Posts: 7

Rep: Reputation: 0
compiling 64 bit kernel in 32 bit environment


I am trying to build 64 bit kernel in 32 bit environment (RH EL5.1) I update .config to
Code:
CONFIG_X86_64=y
CONFIG_64BIT=y
Is this possible? I tried the following:


Code:
$ make ARCH=x86_64 bzImage
  CHK     include/linux/version.h
  CHK     include/linux/utsrelease.h
  UPD     include/linux/utsrelease.h
  CC      arch/x86_64/kernel/asm-offsets.s
arch/x86_64/kernel/asm-offsets.c:1: error: code model ‘kernel’ not supported in the 32 bit mode
arch/x86_64/kernel/asm-offsets.c:1: sorry, unimplemented: 64-bit mode not compiled in
make[1]: *** [arch/x86_64/kernel/asm-offsets.s] Error 1
thanks,

Piotr
 
Old 12-09-2008, 09:06 PM   #2
pinniped
Senior Member
 
Registered: May 2008
Location: planet earth
Distribution: Debian
Posts: 1,732

Rep: Reputation: 50
Yes, it's possible, but you must also set the compiler flag -m64.
 
Old 12-09-2008, 09:35 PM   #3
lazlow
Senior Member
 
Registered: Jan 2006
Posts: 4,363

Rep: Reputation: 172Reputation: 172
As long as you understand that you cannot switch to 64bit RHEL this way.
 
Old 12-10-2008, 07:59 AM   #4
tytus
LQ Newbie
 
Registered: Jan 2005
Location: promanus
Distribution: promanus
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by lazlow View Post
As long as you understand that you cannot switch to 64bit RHEL this way.
I am not trying to switch to 64 bit RHEL. I am just trying to compile a kernel for another machine.
 
Old 12-10-2008, 08:32 AM   #5
tytus
LQ Newbie
 
Registered: Jan 2005
Location: promanus
Distribution: promanus
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by pinniped View Post
Yes, it's possible, but you must also set the compiler flag -m64.
I have tried to add "-m64" to CFLAGS
Code:
CFLAGS += -m64
in the top Makefile but it produced the same result.

In any case even without adding it I see it being added in some places:

Code:
find . -follow -type f -name 'Makefile*' -print0 | xargs -0 -e egrep -n -e "-m64"
./arch/um/Makefile-x86_64:9:CFLAGS += -U__$(SUBARCH)__ -fno-builtin -m64
./arch/um/Makefile-x86_64:10:USER_CFLAGS += -fno-builtin -m64
./arch/um/Makefile-x86_64:11:CHECKFLAGS  += -m64
./arch/um/Makefile-x86_64:12:AFLAGS += -m64
./arch/um/Makefile-x86_64:14:CPPFLAGS += -m64
./arch/um/Makefile-x86_64:22:LINK-y += -m64
./arch/x86_64/Makefile:27:CHECKFLAGS      += -D__x86_64__ -m64
./arch/x86_64/Makefile:39:cflags-y += -m64
./arch/x86_64/Makefile:62:AFLAGS += -m64
But I guess it should be added to every gcc line. Not only in arch/x86_64

Anybody?

Piotr
 
Old 12-10-2008, 10:32 AM   #6
rcbpage
LQ Newbie
 
Registered: Aug 2008
Posts: 27

Rep: Reputation: 0
tytus;

You are doing a cross compile, you have to run the make config, xconfig or menuconfig which ever
is your preference, and set it up for the arch you are going to build for.

then do make CROSS_COMPILE=X86_64-vmlinuz

this is from the Makefile in the top of the kernel src tree:

snip---

# Cross compiling and selecting different set of gcc/bin-utils
# ---------------------------------------------------------------------------
#
# When performing cross compilation for other architectures ARCH shall be set
# to the target architecture. (See arch/* for the possibilities).
# ARCH can be set during invocation of make:
# make ARCH=ia64
# Another way is to have ARCH set in the environment.
# The default ARCH is the host where make is executed.

# CROSS_COMPILE specify the prefix used for all executables used
# during compilation. Only gcc and related bin-utils executables
# are prefixed with $(CROSS_COMPILE).
# CROSS_COMPILE can be set on the command line
# make CROSS_COMPILE=ia64-linux-
# Alternatively CROSS_COMPILE can be set in the environment.
# Default value for CROSS_COMPILE is not to prefix executables
# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile

snap ---

You also have to have the multi-lib gcc & g++ installed.

best of luck

rcb
 
Old 12-10-2008, 03:11 PM   #7
tytus
LQ Newbie
 
Registered: Jan 2005
Location: promanus
Distribution: promanus
Posts: 7

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rcbpage View Post
You also have to have the multi-lib gcc & g++ installed.
Can you elaborate what do you mean by multi-lib gcc and how to get it/build it. Are you talking about building a new instance of gcc for target=x86_64-linux?

Appreciate your help


Piotr
 
Old 12-11-2008, 12:55 AM   #8
rcbpage
LQ Newbie
 
Registered: Aug 2008
Posts: 27

Rep: Reputation: 0
Quote:
Originally Posted by tytus View Post
Can you elaborate what do you mean by multi-lib gcc and how to get it/build it. Are you talking about building a new instance of gcc for target=x86_64-linux?

Appreciate your help


Piotr
Piotr

The multilib libraries are required in order to cross compile various arches
they include the neccesary lib's to compile a 64 bit app in a 32 bit environment
and 32 bit apps in a 64 bit environment.

In your case, assuming you are using gentoo distro

do "emerge --search multilib"

get the flavor's that match the versions of your native gcc and g++ stdc and stdc++

If you are going to upgrade your installed gcc & g++, you should
definitely read the Gentoo howto's on doing this it's a little more involved than
most other distro's, IMHO gentoo is not very developer friendly.
But that just me.
For development work I use Slackware 12.0 stripped to the bones, ie no cruft no
office no bells & whistles just Xfce4 and Eclipse and gedit.
For normal everyday stuff I use Ubuntu 8.041

Gentoo Manual http://www.gentoo.org/doc/en/handbook/index.xml

Gentoo programmers forum http://forums.gentoo.org/viewforum-f-8.html

good luck
Happy Hacking

rcb
 
Old 12-11-2008, 10:24 AM   #9
tytus
LQ Newbie
 
Registered: Jan 2005
Location: promanus
Distribution: promanus
Posts: 7

Original Poster
Rep: Reputation: 0
Thanks rcb,

This solves the question on my Ubuntu box. Ubuntu provides gcc-multilib packages. Here is what I installed on this box (most of them pulled in because of dependencies):
g++-4.2-multilib (4.2.4-1ubuntu3)
gcc-4.2-multilib (4.2.4-1ubuntu3)
lib64gcc1 (1:4.2.4-1ubuntu3)
lib64gomp1 (4.2.4-1ubuntu3)
lib64stdc++6 (4.2.4-1ubuntu3)
libc6-amd64 (2.7-10ubuntu4)
libc6-dev-amd64 (2.7-10ubuntu4)

I was able to compile stock 2.6.18 kernel with this setup with the following command:
Code:
make ARCH=x86_64 bzImage
I did not need to anything to CROSS_COMPILE variable in the top Makefile.
Before compiling I run:
Code:
make ARCH=x86_64 menuconfig
and changing processor type to "Generic X86_64"

However, RedHat does not seem to provide gcc multilib packages and RHEL5 is our official build environment. I wonder if anybody knows how to do this trick on RHEL5.

Any help greatly appreciated.

Piotr
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
compiling 64 bit kernel in 32 bit linux MadnessASAP Linux - Hardware 6 05-04-2009 11:47 AM
compiling 32 bit application on 64 bit linux(x86_64) uttam_h Linux - Software 16 07-19-2008 02:33 PM
compiling in 32-bit mode on 64-bit Linux germanymontrealexpat Linux - Software 2 05-26-2006 07:39 AM
Compiling an AMD64 kernel from a 32-bit environment justinmc Linux - General 3 01-16-2005 06:47 PM
Compiling 32-bit binary in a 64-bit environment Kaj Linux - Software 1 12-13-2004 09:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 11:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration