I'm trying to compile a library which includes some headers from kernel-devel package. I linked the appropriate headers, but now I get compilation errors in those header files.
/usr/include/asm-generic/bitops/fls64.h: In function ‘int fls64(__u64)’:
/usr/include/asm-generic/bitops/fls64.h:10: error: ‘fls’ was not declared in this scope
/usr/include/asm-generic/bitops/fls64.h:11: error: ‘fls’ was not declared in this scope
And, here are the code from asm-generic/bitops/fls64.h
#ifndef _ASM_GENERIC_BITOPS_FLS64_H_
#define _ASM_GENERIC_BITOPS_FLS64_H_
#include <asm/types.h>
static inline int fls64(__u64 x)
{
__u32 h = x >> 32;
if (h)
return fls(h) + 32;
return fls(x);
}
#endif /* _ASM_GENERIC_BITOPS_FLS64_H_ */
As you can notice "return fls(h)", there's no definition of fls(). I can resolve this by including "fls.h", but am I suppose to fix such errors in standard Kernel headers??
Any pointers which could explain why is it this way and what can I do to get around such issues?? Btw, the errors I mentioned here are just the tip of the iceberg. There are a lot of such (delcaration missing) errors in multiple such headers.
Help would be greatly appreciated. Thanks!
rgds/R.
PS: some system details:
Linux Distribution: CentOS (5.5)
[raj#localhost common]$ uname -a
Linux localhost.localdomain 2.6.18-238.9.1.el5 #1 SMP Tue Apr 12 18:10:56 EDT 2011 i686 i686 i386 GNU/Linux
[raj#localhost common]$ cat /proc/version
Linux version 2.6.18-238.9.1.el5 (mockbuild#builder10.centos.org) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-50)) #1 SMP Tue Apr 12 18:10:56 EDT 2011
The root of the problem is that you are using a header file <asm-generic/fls64.h> that is part of the internal kernel implementation and not intended to be used by userspace at all. In fact even in the kernel this header file is just supposed to be included by headers like arch/XXX/include/bitops.h to provide a generic implementation of fls64() based on the fls() defined in architecture-specific code.
In other words the library has a problem in that it is depending on kernel internals that are not really exported to userspace for use and therefore may break for various kernel versions; the library may well have built OK against some older kernel but this was just by luck.
The correct fix is really for the library to provide its own fls64 definition rather than relying on getting lucky about what some random version of kernel headers happens to define by accident.
Related
I have tried building the Linux kernel and I have got some compile errors. Does anyone know what I am doing wrong and how I can fix it? (Or, what additional information do you need?)
Build system is running recent Fedora: 4.19.6-300.fc29.x86_64 #1 SMP Sun Dec 2 17:33:14 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
Target system is a Radxa Rock Pi 4
export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu-
Refer to https://forum.radxa.com/t/building-debian-image-on-gcc8-systems/128/4
Yes, Radxa have a forum, and I have cross-posted there, but I think Stack Overflow has broader experience in this area.
Compile errors follow:
arch/arm64/kernel/vdso.c: In function ‘vdso_init’:
arch/arm64/kernel/vdso.c:119:6: warning: ‘memcmp’ reading 4 bytes from
a region of size 1 [-Wstringop-overflow=] error, forbidden
warning:vdso.c:119 if (memcmp(&vdso_start, "\177ELF", 4)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ make[1]: *** [scripts/Makefile.build:277: arch/arm64/kernel/vdso.o] Error 1
and
fs/exec.c: In function ‘get_task_comm’: fs/exec.c:1084:32: warning:
argument to ‘sizeof’ in ‘strncpy’ call is the same expression as the
source; did you mean to use the size of the destination?
[-Wsizeof-pointer-memaccess] error, forbidden warning:exec.c:1084
strncpy(buf, tsk->comm, sizeof(tsk->comm));
^
Radxa provided the answer, which was to downgrade gcc-aarch64-linux-gnu to version 7 as found in the previous release of Fedora.
The best way to fix this problem is to use a compiler which matches the age of the kernel you are trying to compile.
To do this, use a prebuilt compiler, install it into /usr/local and define it as the CROSS_COMPILE variable :
wget https://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz
sudo tar xvf gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz -C /usr/local/
export CROSS_COMPILE=/usr/local/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-
Now you can make your kernel like so :
export ARCH=arm64
make
Otherwise, to fix your bug specifically, change the following (in arch/arm64/kernel/vdso.c) :
extern char vdso_start, vdso_end;
To this :
extern char vdso_start[], vdso_end[];
Also change all references to
&vdso_start
to the following
vdso_start
However, unfortunately this will only solve the very first of a large number of bugs.
I want to copile a simple c program ("Hello world") for my Xtreamer prodigy. which runs a basic linux kernel:
/host # uname -a
Linux Prodigy 2.6.34-VENUS #30 PREEMPT Tue Feb 28 13:48:27 CST 2012 mips GNU/Linux
(it using chipset Realtek 1186)
I saw one executable file on the streamer and i "filed" it on linux and i got:
sh-4.1# file DvdPlayer
DvdPlayer: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked (uses shared libs), with unknown capability 0xf41 = 0x756e6700, with unknown capability 0x70100 = 0x1040000, stripped
On my computer I run linux centos. what compiler do I need to use and when can I get it?
Thanks!
What you need is a cross toolchain - gcc has a architecture that enables it to have different code generation backends, mainly to be able to compile for other architectures than the one you're developing on.
Lots of precompiled cross toolchains exist, an overview of ready to use toolchains for MIPS can be found here.
On the other hand, creating your own cross tool chain, finetuned to your needs, isn't that hard either, it's just quite a bit of work. The canonical reference on how to generate a cross toolchain is Dan Kegel's page.
When I try to compile one of my old program which uses ext3 structure with new Fedora 16
I get the message
# make
Compile main.c In file included from main.c:8:0:
giis.h:18:28: fatal error: linux/ext3_fs.h: No such file or directory
compilation terminated.
I did yum install kernel-devel and kernel-headers - but still it gives above message.
# uname -a
Linux space 3.2.9-2.fc16.x86_64 #1 SMP Mon Mar 5 20:55:39 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
The linux kernel does not export a header called ext3_fs.h, or does not do so anymore. Edit your giis.h to do without it. See commit v2.6.25-rc8~52: “Neither of the headers actually compiles when included from userpsace nor should it be made available as userspace tools should be using the libraries or at least headers from e2fsprogs.”
I have been searching google and tbbs forums on how to install TBB.
I have downloaded both the linux and source from:
http://threadingbuildingblocks.org/ver.php?fid=175
Extracted them using tar -xvf, and then ran the make file.
Then I went to tbb/build/linux_intel64_gcc_cc4.5.2_libc,13_kernel2.6.38_debug/ and ran tbbvars.sh
I also tried running tbb/build/generate_tbbvars.sh, then tbbvars.sh and tbbvars.csh
No matter what I ty when I try to compile a program with -ltbb, i get
/usr/bin/ld: skipping incompatible /usr/lib/libtbb.so when searching for -ltbb
/usr/bin/ld: cannot find -ltbb
Any one know how to fix this?
Linux damian-HP-Z600-Workstation 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:24 UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
This is another instance of the issue answered lucidly here. You have libraries of one bit width and are trying to link them into a compilation of a different bit width. If both your application compile process and your TBB build process were done on the same system, one of them must have done the wrong thing when deciding whether to output 32-bit code or 64-bit code.
I have an application compiled at:
gcc version 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)
Linux debian 2.6.18-5-686 #1 SMP Fri Jun 1 00:47:00 UTC 2007 i686 GNU/Linux
and it runs well.
Now I want to run it at:
Linux 2.4.20_mvlcge31-tomas #7 Thu May 7 11:33:21 CEST 2009 i686 unknown
I got following errors:
libstdc++.so.6: cannot handle TLS data
From the web I saw someone suggested to do this: export LD_ASSUME_KERNEL=2.2.5
I tried but get even more errors:
ls: error while loading shared libraries: librt.so.1: cannot open shared object file: No such file or directory
Who can help me with it? thanks
You had compiled the application against much newer libc and kernel version, You can't compile program on 2.6 with newest libc and expect it to run on old kernel.
Also where do you actually still use Linux 2.4?