Kernel compilation error - c

I was trying to compile the Linux kernel.
I am getting the following error:-
"No rule to make target arch/x86/kernel/entry_32.o', needed byarch/x86/kernel/built-in.o'."
Before this I configured the kernel(didn't do anything extra except the default options).
configured the kernel using "make gconfig". The config was generated. I am using x86 32 bit machine (Fedora 9) kernel version 2.6.30.
Finally I used :-
"make bzImage"
to compile.
Tried to search the net for a solution but without success.
How to fix these errors??
Kindly help.
Thanks,
Sourabh

You need to call make before make bzImage.
make clean or make mrproper would perhaps help too depending how much you screwed up already.

I agree with the previous answer, you should take a look at how to compile a kernel, the fedora way (here). Not sure this is still up-to-date, but leveraging the provided tools is a good idea sometimes.

Maybe you didn't actually configure the kernel. Did you use any of "make config", "make menuconfig", "make xconfig"?
Are you running an x86 distribution or an x86_64 one? In the latter case, you need the x86 32 bits compilation environment too.
Advice : this is a poorly asked question. You didn't give any relevant information : Linux distribution and architecture, kernel version you want to compile, the commands you tried and the messages you got.

Related

The Linux kernels 3.* series won't boot properly upon being customly compiled in Ubuntu 16.04.1 by means of make-kpkg and gcc-4.8.5

Recently I upgraded up to Ubuntu 16.04.1 Xenial (from 14.04 Trusty) the build-host where I've compiled different linux kernels so far for my own project. Ubuntu 16.04.1 implies using a new updated environment for building binaries. These tools include a new gcc-5.4, libc6 (for userspace applications), etc. Also a new Ubuntu supplies (or suggests) a new kernel-package containing a new make-kpkg script and pulling different dependencies like build-essential, binutils, etc. with it
Ok, my task is to compile a linux kernel v3.10.12 (or v3.19) and run it within a VirtualBox machine (architecture x86_64, system Ubuntu 16.04.1). I used to be able to compile kernel-v3.10.12 and kernel-v3.19 in Ubuntu 14.04 Trusty deployed on the build server with the compiler gcc-4.8 and launch the kernels under the VirtualBox machine I mentioned above, but now something goes wrong while starting a kernel compiled
For example, let's consider v3.10.12 being compiled and run
For building the kernel I utilize 'make-kpkg' script provided by Ubuntu aptitude's package 'kernel-package'. I build the kernel for x86_64 using gcc-4.8 as I have always been doing
Once 'make-kpkg' has compiled the kernel and gathered linux-headers it starts packing them into deb-packages what makes me able to execute 'dpkg -i' on them in the system and install them in a 'debian' way
Okey, supposing I did it. Then I am going to reboot the system
When I choose my compiled kernel in the grub menu, it writes in the screen "Loading linux kernel... Loading initial ramdisk", then the inscription disappears, the screen goes black and I see only a cursor in the form of underscore "_" sign in the top-left side of the screen. That's all. Nothing is going to happen further. The booting process seems to have stuck
I tried swapping make-kpkg for an old one (from Trusty), swapping compiler gcc-4.8.5 for gcc-4.9, gcc-4.7, even gcc-5.2 having made a couple of supplementations inside the directory include/linux/ for the support of gcc-5.2, but nothing has come off, the result still persists being the same
I tried the same actions (on the same Ubuntu 16.04.1 and tool-chain) with new kernels 4. series* (for example, 4.6) meaning building the kernels, packing them into *.deb packages and installing into the VirtualBox machine and rebooting the system, and everything goes correctly, I see debug messages in the screen like I have always seen. I tried to use gcc-4.7, gcc-4.8, gcc-4.9, gcc-5.4 and everything works, I am able to load the linux-kernel-v4.6 appropriately and completely. But when I build 3.10.12 (or 3.19) kernels I cannot boot them properly and cannot have figured out why it has been happening
Actually, what I have found out is that the deal is in the kernel but not in initrd because I managed to substitute the 'broken' kernel by a working one having left 'initrd' built together with the 'broken' kernel and the debug logging started appearing and the kernel was loading until a rootfs came out to be mounted, at that moment the kernel didn't manage to load it and left in initramfs mode
Has someone faced the same issue I am observing? Actually I am almost exhausted having been struggling with this trouble for days
Maybe someone has any recipes or suggestion how to get rid of the problem?
I even put the 'panic' function code exactly in the first line of the function "asmlinkage void __init start_kernel(void)" but nothing happened, still the same black screen
Can the problem be related to a new glibc being used by gcc compiling my kernel? Personally, I am not prone to think so but in the world of linux everything can happen. On the other hand maybe toolchain (ld, as) somehow has affected? I am kindly asking to provide me a help.
I am nearly assured that someone before me has already encountered such an issue, I would have been searching for a topic alike but didn't find anything resembling
Thank you in advance
Short Answer
It's a glibc kernel version mismatch, if you need this you could create the glibc package such that it supports the kernel version that you need, by using the --enable-kernel flag at configuration time.
Long Answer
It's highly likely that your glibc was compiled in such a way that it only works down to a certain version of linux. This is done with the help of the --enable-kernel flag at the configuration stage. Any version older than the one specified in --enable-kernel will be rejected by glibc as a consequence no program will ever be loaded, like the init program presumably systemd's init.
This is from the configuration help of glibc
--enable-kernel=version
This option is currently only
useful on GNU/Linux systems. The version parameter should have the form X.Y.Z and describes the smallest version of the Linux kernel the generated library is expected to support. The higher the version number is, the less compatibility code is added, and the faster the code gets.
Finally I succeeded in this problem
Actually what I have done is to have compiled an old gcc-4.8.5 with an old glibc-2.19 on the host-system where I build the old-versioned kernels.
Glibc-2.19 was compiled with an option --enable-kernel=3.10.12 and with headers of an old-versioned linux-3.10.12. The compiler has turned out to be like a 'cross-compiler' with usage of glibc-2.19. So, I built an old kernel with the version 3.10.12 with this 'cross-compiler', which uses glibc-2.19, and everything has started working in a proper way
Thanks for the help and directing me to a right way to solve the problem, but I am obliged to notice that the deal was in host-system's glibc used but not in target-system glibc used as I had been assumedly said (but maybe I misunderstood #iharob)

How to add a flag (such as -g) to the whole project (created by someone else)?

I have a library I am using (which is critical to my work) that I am suspecting may have a bug. Unfortunately, the owner of the library is not so responsive as to trying out my sample codes. I am about to try debugging it myself.
To be more honest, it's not just a library, it's a library plus a set of kernel modules and the crash happens at kernel level (pretty nasty) and indeed would be hard to spot for the owner of the code too.
Sometimes that I get lucky, I get a kernel oops, that if I could build his code with -g option, I can find which line the error occurs (which greatly help, since I have just started facing huge amounts of his code with pretty much no clue).
Now the GNUmakefiles of the project are built with automake (I believe). My question is How can I tell make to add -g to CFLAGS throught the WHOLE build?
I remember reading something along the lines of how to write Makefiles so that "external" options can be added etc, but I neither know whether these makefiles would be generated with that ability (which should because it's automake), or how those external options are given anyway!
I am guessing something like this:
make CFLAGS=-g
should do it, but honestly have no idea.
Edit: Note that, I am actually interested in the -g flag to be included when the kernel modules are being built. I cannot use try and error (for example with my command above) to see if works or not, as the kernel build just prints [CC] ... without showing any options!
Edit: Well actually I did try, but gdb ./module.ko still claims there are no debug symbols.
Is there a configure script? If so, was it created by autoconf? (Probably.) Then you can do
./configure CFLAGS='-g -O0'
make clean
make
to rebuild the whole thing with debugging on and optimization off.
Otherwise, no-one can really help you unless you provide a relevant excerpt of the makefile.

Issue with gdb on ubuntu with gcc 4.4.3

i am using gcc 4.4.3 on ubuntu 10.4 32bit machine.
i use 'gdb' to debug my code. Since few days i am seeing that whenever i debug code gdb steps into the c library functions used in the code also(like printf,fgets etc). This shows a long list of calls from one function to other.see the attached screen shot.
Previously gdb was working fine just stepping over my own code.
Maybe i am being novice !! But it is sometimes really irritating when gdb shows me numerous lines which i am not interested in the present context.
If someone can guide me as in how to turn off/on this feature and what can be cause of it being switched on on its own(i don't remember doing anything).
Many thanks.
i used to do that previously also but then it never went into any of the lib functions
You (or someone) have installed libc6-dbg package. Before that, GDB couldn't step into libc functions, because they didn't have any debug info. Now they do, and it can.
Either get out of the habit of typing step when you want next, or un-install libc6-dbg.

Building a Linux Kernel with Visual Studio 2010 [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Does anyone have step-by-step instructions on how to build a Linux kernel using Visual Studio 2010?
I've tried to search for the solution to this question directly, but no joy. A few things I have been able to find out:
The Linux kernel is built using the GNU C compiler, so a prerequisite would be to build a Windows GNU C compiler, in order to compile a Linux GNU C compiler. I realize the GNU C compiler source code is available from GNU.org, but has anyone actually built the GNU C compiler for Windows using the Microsoft Visual Studio 2010 C/C++ compiler?
Once the Linux GNU C compiler is made, I can use it to build the Linux kernel, along with any other Linux-based software needed to get a Linux system up and going. This is what I got from www.linuxfromscratch.org
Some of you may be wondering why I don't simply download a pre-compiled GNU C compiler for this? The environment I'm working in is completely separated from any outside network. Even sneaker-net is not allowed. Every bit of software will have to be compiled from source, and those sources will have to be typed in by hand. It's inefficient, but it's also paranoid-secure. (Don't ask, I'm not the boss...)
Anyway, we're looking at bringing up in-house Linux boxes, but we're starting with Windows 7 and Visual Studio 2010. Can someone please advise how we can turn all that re-typed source code into a working GNU C compiler for Windows? And also for Linux?
Thanks for any advice!
I think that Ken Thompson's "Reflections on Trusting Trust" explains very well how futile and not paranoid enough is this idea.
You can't trust
code that you did not totally create
yourself. (Especially code from
companies that employ people like me.)
No amount of source-level verification
or scrutiny will protect you from
using untrusted code.
How do you know that the compiler you are going to use to build GCC is secure if you didn't compile it yourself from source? And the compiler you used for that?
You need to type in by hand the machine code for a compiler to bootstrap your 100% secure environment. Only then can you trust compiled source code, whether you typed it in by hand or not.
Fact: you need gcc to compile a kernel.
Fact: you need kernel source to compile a kernel.
Once you have those two, you can bootstrap a working kernel, targeted for any platform you wish.
You can do all this on any platform you wish. For example, you can build a Linux kernel on Windows. You can just as easily build a Linux kernel for ARM or PPC on Windows.
But you've got to have the kernel source and the gcc compiler to get started.
And both the kernel source as well as gcc source depend on literally thousands headers and .c files. They're simply not practical to key in by hand.
IMHO...
If you're going to build a kernel, use a Linux distribution. There is no point in building one under Windows. Even if you'll be making your own Linux, still use Linux for that.
You could always try cygwin, but I doubt that will do you much good, even if you install all the packages.
Fabrice Bellards tcc is able to compile Linux.
It's so small you can probably compile it in Visual C++ (or modify until it works).
You could also try his qemu to simulate a computer.
Recently he even implemented a x86 virtual machine in Javascript, so you can run everything within your browser.
Even sneaker-net is not allowed. Every bit of software will have to be compiled from source, and those sources will have to be typed in by hand. It's inefficient, but it's also paranoid-secure.
Tell your boss that having someone type source code by hand is going to do nothing but induce bugs. If they want Linux boxes, then they're going to have to use the source code for Linux. You guys didn't type in all the Windows 7 source code by hand either, did you? The kernel is some 13.5 million lines of source code. There's no way you're going to be able to type that all out without inducing a ton if typo-related bugs, and that's less secure than just copying the source.
Your boss needs to get it through his head that even just typing that much code, even if the person in question was a 100% perfect typists, would take years.
By typing the whole code you mean copying/retyping every single line of code?
Please, allow me to ask, how different of the original code is this going to be?
If you're just copying, you're not fixing bugs nor checking possible vulnerabilities. Are you? I'd rather spend the respective amount of time reviewing the actual code and reporting or fixing the problems you occasionaly find.
Okay. That is almost impossible.
How you could do it:
Download virtualbox
Download an Ubuntu iso
Install Virtualbox
Create and install an Ubuntu Virtual Machine
On that virutal machine's terminal:
sudo apt-get build-essential
wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.39.2.tar.bz2
tar vxjf linux-2.6.39.2.tar.bz2
cd linux-2.6.39.2
make menuconfig ; make
Or something like that...
Assuming this question isn't a troll (is that possible?)... Maybe you're planning to OCR the source into your system, like how PGP used to get around encryption software export restrictions.
But I don't think you'll have any luck building GCC using MSVC, regardless of how many monkeys might be typing in the source. From http://gcc.gnu.org/install/specific.html:
GCC will build under Cygwin without modification; it does not build with Microsoft's C++ compiler and there are no plans to make it do so.
Of course, if you do manage to ever get GCC onto the system under the conditions you give, and you get the Linux kernel source there somehow, I think you'll run into difficulties cross compiling Linux under a Windows-based GCC cross compiler. If nothing else, the Linux source tree and build environment depend at least a little bit on the case-sensitive nature of Unix file systems (ie., they depend on the fact that fielname can differ only in the case of characters). Windows doesn't deal well with filename that differ only by case (I think that NTFS can be configured somehow to support them, but the Win32 subsystem will almost certainly be hopelessly confused).
I'm sure there are other hurdles.

Trying to compile code from OS Dev tutorial

This is a hard question to ask because I'm positive I'm about to be bombarded with haters commenting on "if I can't write an operating system already, I won't ever to be able to write an operating system". Well I've read Modern OS by Tanembaum, Linux Kernel Development, Understanding the Linux kernel and others I still don't know if or not I can write an operating system and only by pushing forward to write one will I realise what I don't know. On top of that none of the books I read even bother to describe the boot sequence / compilation sequence.
Anyway I hate to be negative but I would just like to build the example code from the bkerndev tutorial below and have an absolutely minimum operating system:
http://www.osdever.net/bkerndev/index.php?the_id=90
You can download the associated source code in a zip format from here:
http://www.osdever.net/bkerndev/bkerndev.zip
When you try and compile this kernel you run into all sorts of errors caused by the fact that some of the code is broken. Another user was seeking help for this here on stack overflow here:
compiling my own kernel (not from linux-kernel source)
Although didn't get much help. I have addressed those errors by adding the gcc flag fleading-underscores and by changing some of the data types. You can see my code here:
http://github.com/PhillipTaylor/farmix
The code will compile sucessfully and leave me with a kernel.bin executable but when I boot into it from grub I get:
Error 13: Unrecognised or unsupported format (or something to that nature)
When I take the kernel.bin directly from the authors zip file and run it on my eeepc it boots absolutely fine so I think I have a problem with compiling the code correctly. The author is building it from a Windows machine, I believe, but I am trying to compile it using Fedora 10 i386 with GNU GCC 4.3 and I think this is what is causing the issue so I ask you, how do I build a valid executable kernel? Am I missing the correct target or the wrong binary format?
I would really appreciate someone helping me over this embarrassing "first step"
My comment above wasn't very clear. What I meant is "What does the 'file' command report on your kernel.bin vs. theirs?". The output of the linker is a raw binary file. It should start with a few magic words that grub recognizes. They are defined in start.asm near "mboot". I suspect yours is different than theirs.
I don't have nasm handy so I can't build, but you might want to start by comparing the first few words of the .bin file.
It turns out that the line used to compile the app was explicitly set to compile to "aout" format which was what the guide said and what I assumed to be true. Only reading stuff in the "barebones" guide convinced me that I may have been confused. As soon as I changed that one line to "nasm -f elf" it all worked.
This is a tag in my repository that points to a basic WORKING version of bkerndev tutorial code (How to write your own Operating system) for future reference and people who were in my position..
It comes with a makefile for building it from a 32 bit Linux system.
http://github.com/PhillipTaylor/farmix/tree/bkerndev_tutorial_working

Resources