elfutils-libelf isn’t libelf!

These days, I am suffering with building ktap on Suse. Since Suse doesn’t provide elfutils-libelf-devel nor libelf-devel, so I decide to build libelf from source code.

First, I install the newest version (0.8.13) from libelf site. Building ktap generate the following errors:

cc  -Wall -O2  -o userspace/kp_main.o -c userspace/kp_main.c
In file included from /usr/local/include/libelf/libelf.h:25:0,
                 from /usr/local/include/libelf/gelf.h:28,
                 from /usr/local/include/gelf.h:1,
                 from userspace/kp_symbol.h:28,
                 from userspace/kp_main.c:40:
/usr/lib64/gcc/x86_64-suse-linux/4.8/include/stddef.h:147:26: error: conflicting types for ‘ptrdiff_t’
 typedef __PTRDIFF_TYPE__ ptrdiff_t;
                          ^
In file included from userspace/kp_main.c:37:0:
userspace/../include/ktap_types.h:20:13: note: previous declaration of ‘ptrdiff_t’ was here
 typedef int ptrdiff_t;
             ^
Makefile:119: recipe for target 'userspace/kp_main.o' failed
make: *** [userspace/kp_main.o] Error 1

The root cause is in this version, libelf.h contains stddef.h which defines ptrdiff_t, while ktap_types.h also defines it. So I decide to use an older version of libelf.

Second, I install the 0.8.5 version of libelf. This time, the compilation generates the following errors:

userspace/kp_symbol.c: In function ‘find_load_address’:
userspace/kp_symbol.c:69:2: warning: implicit declaration of function ‘elf_getphdrnum’ [-Wimplicit-function-declaration]
  if (elf_getphdrnum(elf, &phdrnum))
  ^
userspace/kp_symbol.c: At top level:
userspace/kp_symbol.c:189:44: error: unknown type name ‘GElf_Nhdr’
 static const char *sdt_note_name(Elf *elf, GElf_Nhdr *nhdr, const char *data)
                                            ^
userspace/kp_symbol.c: In function ‘dso_sdt_notes’:
userspace/kp_symbol.c:215:2: error: unknown type name ‘GElf_Nhdr’
  GElf_Nhdr nhdr;
  ^
userspace/kp_symbol.c:222:2: warning: implicit declaration of function ‘elf_getshdrstrndx’ [-Wimplicit-function-declaration]
  if (elf_getshdrstrndx(elf, &shstrndx) != 0)
  ^
userspace/kp_symbol.c:238:3: warning: implicit declaration of function ‘gelf_getnote’ [-Wimplicit-function-declaration]
   (next = gelf_getnote(data, offset, &nhdr, &name_off, &desc_off)) > 0;
   ^
userspace/kp_symbol.c:243:11: error: request for member ‘n_namesz’ in something not a structure or union
   if (nhdr.n_namesz != sizeof(SDT_NOTE_NAME) ||
           ^
userspace/kp_symbol.c:248:3: warning: implicit declaration of function ‘sdt_note_name’ [-Wimplicit-function-declaration]
   name = sdt_note_name(elf, &nhdr, sdt_note_data(data, desc_off));
   ^
userspace/kp_symbol.c:248:8: warning: assignment makes pointer from integer without a cast [enabled by default]
   name = sdt_note_name(elf, &nhdr, sdt_note_data(data, desc_off));
        ^
userspace/kp_symbol.c:253:10: error: request for member ‘n_descsz’ in something not a structure or union
      nhdr.n_descsz, nhdr.n_type);
          ^
userspace/kp_symbol.c:253:25: error: request for member ‘n_type’ in something not a structure or union
      nhdr.n_descsz, nhdr.n_type);
                         ^
Makefile:134: recipe for target 'userspace/kp_symbol.o' failed
make: *** [userspace/kp_symbol.o] Error 1

After googling, I find this issue: elfutils-libelf isn’t libelf! So I install elfutils-libelf from source code (please refer this post), then the build of ktap is OK!

 

Build elfutils-libelf from source code

Since there is no elfutils-libelf-devel package for Suse, so I need to build it from source code. The steps are as follow:

(1) Download elfutils from here;

(2) Uncompress source package:

tar xvf elfutils-0.163.tar.bz2

(3) Do the configuration:

cd ./elfutils-0.163
elfutils-0.163 # ./configire

(4) Compile and install libelf:

elfutils-0.163 # cd libelf
elfutils-0.163/libelf # make
elfutils-0.163/libelf # make install

Build other modules, such as libcpu is same.

 

Install git-email on RHEL 7.0

The RHEL 7.0 ISO doesn’t provide git-email rpm package by default. Because the git rpm provided by ISO file isgit-1.8.3.1-4.el7.x86_64.rpm, you should download the same version here, and install it:

[root@linux ~]# rpm -ivh git-email-1.8.3.1-4.el7.noarch.rpm
warning: git-email-1.8.3.1-4.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
        perl(Authen::SASL) is needed by git-email-1.8.3.1-4.el7.noarch
        perl(Net::SMTP::SSL) is needed by git-email-1.8.3.1-4.el7.noarch

From the error message, we know also need to use yum to install perl-Net-SMTP-SSL and perl-Authen-SASL packages:

[root@linux ~]#yum install perl-Net-SMTP-SSL
[root@linux ~]#yum install perl-Authen-SASL

Done!

 

Why does chainloader complain “invalid signature”?

My computer has multiple harddisks and every disk has multiple partitions. I install the SLES (Suse Linux Enterprise Server) on the 5thpartition of the 2nd harddisk, but find it can’t boot:

grub> set root="(hd1,msdos5)"
grub> chainloader +1
error: invalid signature.

After checking installation steps, I find by default, the SLES can’t install bootcode on the partition:

1

Click the install option in the above picture, then it will install the bootcode :

2

then the boot process is OK!

 

Install ktap on RHEL

My RHEL is 7.0, the minimal installation. Build ktap, it outputs the following error:

[root@redhat ktap-master]# make
    CHK libelf
Makefile:108: No libelf found, disables symbol resolving, please install elfutils-libelf-devel/libelf-dev
make -C /lib/modules/3.10.0-123.el7.x86_64/build M=/root/ktap-master modules
make: *** /lib/modules/3.10.0-123.el7.x86_64/build: No such file or directory.  Stop.
make: *** [mod] Error 2

(1)

To fix “No libelf found, disables ...” error, you need to install elfutils-libelf-devel package:

[root@redhat ktap-master]# yum install elfutils-libelf-devel
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package elfutils-libelf-devel.x86_64 0:0.158-3.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved
......

(2)

To fix “*** /lib/modules/3.10.0-123.el7.x86_64/build: No such file or directory.” error, you need to install kernel-devel package:

[root@redhat ktap-master]# yum install kernel-devel
Loaded plugins: product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package kernel-devel.x86_64 0:3.10.0-123.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

Then make is OK!