Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 12 Sep 2006 14:45:37 +0200
From:      Marcin Cieslak <saper@SYSTEM.PL>
To:        emulation@freebsd.org
Subject:   report by LTP: "2.4+ kernel w/o ELF notes? [long] 
Message-ID:  <4506ABF1.6010407@SYSTEM.PL>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------010009050207000304010904
Content-Type: text/plain; charset=ISO-8859-2; format=flowed
Content-Transfer-Encoding: 7bit

Having finally installed and run ltp I've had a look at this issue.

The message comes from tools/top-LTP/proc/sysinfo.c where function 
init_libproc() tries to find out the number of clock ticks per second
(see some discussion at http://comments.gmane.org/gmane.linux.kernel/190241).

The message is a bit misleading, I think that PT_NOTE is actually something 
different - it's a special ELF section that provides Linux-way of doing 
brandelf(1). Feel free to run "elfdump -n" on any FreeBSD and Linux binary to 
find out the difference.

Nice introduction to PT_NOTE:
http://netbsd.org/Documentation/kernel/elf-notes.html

On a side note I think that understanding ELF interpreter entry (elfdump -i)
and notes is a key to understand ld-linux.2 vs. brandelf issue we discussed 
previously.

Coming back to the problem with clock ticks:

Number of clock ticks per second is provided in Linux via auxiliary arguments 
provided to the application right after its environment.
The POSIX way to fetch this information in the application is 
sysconf(_SC_CLK_TCK). This value is currently fixed on the FreeBSD to 128.

I wrote a small program to read auxiliary arguments (attached).

Linux binary run under FreeBSD returns:

% ./linux_t
program headers for program [0x00000003], 0x08048034
size of program header entry [0x00000004], 0x00000020
number of program headers [0x00000005], 0x00000008
system page size [0x00000006], 0x00001000
flags [0x00000008], 0x00000000
entry point of program [0x00000009], 0x08048320
base address of interpreter [0x00000007], 0x48049000
real uid [0x0000000b], 0x000000a9
effective uid [0x0000000c], 0x000000a9
real gid [0x0000000d], 0x0000000a
effective gid [0x0000000e], 0x0000000a

Linux binary run under FC3 on sparc64 gives:

arch dependent hints at CPU capabilities [0x00000010], 0x0000001f
system page size [0x00000006], 0x00002000
frequency at which times() increments [0x00000011], 0x00000064
program headers for program [0x00000003], 0x00010034
size of program header entry [0x00000004], 0x00000020
number of program headers [0x00000005], 0x00000007
base address of interpreter [0x00000007], 0x70000000
flags [0x00000008], 0x00000000
entry point of program [0x00000009], 0x00010310
real uid [0x0000000b], 0x000012ad
effective uid [0x0000000c], 0x000012ad
real gid [0x0000000d], 0x000012ad
effective gid [0x0000000e], 0x000012ad
unknown [0x00000017], 0x00000000

Linux binary on 32-bit i386 on OpenSuSE 10.0:

arch dependent hints at CPU capabilities [0x00000010], 0x0383fbff
system page size [0x00000006], 0x00001000
frequency at which times() increments [0x00000011], 0x00000064
program headers for program [0x00000003], 0x08048034
size of program header entry [0x00000004], 0x00000020
number of program headers [0x00000005], 0x00000008
base address of interpreter [0x00000007], 0x40000000
flags [0x00000008], 0x00000000
entry point of program [0x00000009], 0x08048320
real uid [0x0000000b], 0x000003e8
effective uid [0x0000000c], 0x000003e8
real gid [0x0000000d], 0x00000064
effective gid [0x0000000e], 0x00000064
unknown [0x00000017], 0x00000000
string identifying CPU for optimizations [0x0000000f], 0xbfd4356b

I guess that some CPU-optimizing programs could benefit from adding
AT_PLATFORM, AT_HWCAP and AT_CLKTCK.

I guess that adding AT_CLKTCK should be just something like adding one line in
elf_linux_fixup() of ${arch}/linux/linux_sysvec.c.
Adding "AUXARGS_ENTRY(pos, 17, 100)" before AUXARGS_ENTRY(pos, AT_NULL...) at 
least silences the ltp test program.

Therefore we should put implementing of AT_PLATFORM, AT_HWCAP, AT_CLKTCK and
possibly AT_SECURE on our TO-DO list. It may help us to deal with glibc 
incompatibilities.

-- 
               << Marcin Cieslak // saper@system.pl >>

--------------010009050207000304010904
Content-Type: text/plain;
 name="t.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="t.c"

#include <stdio.h>
#include "linux_elf.h"

#define AT_EOF ((unsigned long)0xFFFFFFFF)
struct nmap {
	unsigned long nm_id;
	const char *nm_name;
} note_map[] = {
  {AT_NULL, "end of vector"}, 
  {AT_IGNORE, "entry should be ignored"}, 
  {AT_EXECFD, "file descriptor of program"}, 
  {AT_PHDR, "program headers for program"}, 
  {AT_PHENT, "size of program header entry"}, 
  {AT_PHNUM, "number of program headers"}, 
  {AT_PAGESZ, "system page size"}, 
  {AT_BASE, "base address of interpreter"}, 
  {AT_FLAGS, "flags"}, 
  {AT_ENTRY, "entry point of program"}, 
  {AT_NOTELF, "program is not ELF"}, 
  {AT_UID, "real uid"}, 
  {AT_EUID, "effective uid"}, 
  {AT_GID, "real gid"}, 
  {AT_EGID, "effective gid"}, 
  {AT_PLATFORM, "string identifying CPU for optimizations"}, 
  {AT_HWCAP, "arch dependent hints at CPU capabilities"}, 
  {AT_CLKTCK, "frequency at which times() increments"}, 
  {AT_EOF, "unknown"},
};


int
main(int argc, char *argv[], char *environ[]) {
	unsigned long *ep = (unsigned long *) environ;
	struct nmap *search;
	int i;
	while(*ep++);	
	while (*ep) {
		for (search = note_map; search->nm_id != AT_EOF; search ++) 
			if (search->nm_id == ep[0])
				break;
		printf("%s [0x%08lx], 0x%08lx\n", search->nm_name, ep[0], ep[1]);
		ep+=2 ;
	}
}


--------------010009050207000304010904--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4506ABF1.6010407>