public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* linux object file containing all kernel symbols and suitable for userspace linking?
@ 2008-09-28  2:57 Daniel Rosenthal
  2008-09-28  3:13 ` Grant Coady
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Rosenthal @ 2008-09-28  2:57 UTC (permalink / raw)
  To: linux-kernel; +Cc: jdike

Is there an object file generated by the kernel build process just
before vmlinuz and arch/x86/boot/bzImage are created that contains all
the requisite kernel symbols to complete compilation?  I understand
that such an object file wouldn't make a lot of sense to keep around,
because at the point at which such a file were able to be generated
the compilation process could just be completed instead.  If it's not
available is there some easy way to generate it?  I am trying to test
some kernel code I wrote, and I wanted to test it by running it in
userspace by linking it to a *.o file with a main() function (just to
test out various API facilities; i.e. unit tests).  This is so I can
use the API provided by the kernel without having to rewrite it for
userspace.  User-Mode Linux won't work for this because the code in
question relies on some architecture specific features and thread
flags of x86, but I guess the approach would probably similar to what
UML uses.

Is there some simple way to do this?

Thanks,
Daniel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: linux object file containing all kernel symbols and suitable for userspace linking?
  2008-09-28  2:57 linux object file containing all kernel symbols and suitable for userspace linking? Daniel Rosenthal
@ 2008-09-28  3:13 ` Grant Coady
  2008-09-28  7:22   ` Daniel Rosenthal
  0 siblings, 1 reply; 5+ messages in thread
From: Grant Coady @ 2008-09-28  3:13 UTC (permalink / raw)
  To: Daniel Rosenthal; +Cc: linux-kernel, jdike

On Sat, 27 Sep 2008 22:57:10 -0400, "Daniel Rosenthal" <danielrosenthal@acm.org> wrote:

>Is there an object file generated by the kernel build process just
>before vmlinuz and arch/x86/boot/bzImage are created that contains all
>the requisite kernel symbols to complete compilation?  I understand
>that such an object file wouldn't make a lot of sense to keep around,
>because at the point at which such a file were able to be generated
>the compilation process could just be completed instead.  If it's not
>available is there some easy way to generate it?  I am trying to test
>some kernel code I wrote, and I wanted to test it by running it in
>userspace by linking it to a *.o file with a main() function (just to
>test out various API facilities; i.e. unit tests).  This is so I can
>use the API provided by the kernel without having to rewrite it for
>userspace.  User-Mode Linux won't work for this because the code in
>question relies on some architecture specific features and thread
>flags of x86, but I guess the approach would probably similar to what
>UML uses.

There's a vmlinux.o in top-level directory after a kernel compile, is 
that what you're after?

Grant.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: linux object file containing all kernel symbols and suitable for userspace linking?
  2008-09-28  3:13 ` Grant Coady
@ 2008-09-28  7:22   ` Daniel Rosenthal
  2008-09-28 14:06     ` Jeff Dike
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel Rosenthal @ 2008-09-28  7:22 UTC (permalink / raw)
  To: Grant Coady; +Cc: linux-kernel

On Sat, Sep 27, 2008 at 11:13 PM, Grant Coady wrote:
> There's a vmlinux.o in top-level directory after a kernel compile, is
> that what you're after?

It's looks close, but it seems to be missing some symbols.  Below is
an excerpt of some of the some of the error messages that come up when
trying to link vmlinux.o to another object file.  It looks like all
the binary layout related symbols are missing, and jiffies also.
How/when are these symbols normally linked into the final kernel
image?

Daniel


...
/usr/src/linux/vmlinux.o: In function `sched_clock':
/usr/src/linux/kernel/sched.c:80: undefined reference to `jiffies'
/usr/src/linux/vmlinux.o: In function `__might_sleep':
/usr/src/linux/kernel/sched.c:7478: undefined reference to `jiffies'
/usr/src/linux/kernel/sched.c:7480: undefined reference to `jiffies'
/usr/src/linux/vmlinux.o: In function `in_sched_functions':
/usr/src/linux/kernel/sched.c:7289: undefined reference to `__sched_text_start'
/usr/src/linux/kernel/sched.c:7289: undefined reference to `__sched_text_end'
/usr/src/linux/vmlinux.o: In function `print_cpu':
/usr/src/linux/kernel/sched_debug.c:174: undefined reference to `jiffies'
/usr/src/linux/kernel/sched_debug.c:174: undefined reference to `jiffies'
/usr/src/linux/vmlinux.o: In function `printk_timed_ratelimit':
/usr/src/linux/kernel/printk.c:1343: undefined reference to `jiffies'
/usr/src/linux/kernel/printk.c:1344: undefined reference to `jiffies'
/usr/src/linux/vmlinux.o: In function `zap_locks':
/usr/src/linux/kernel/printk.c:550: undefined reference to `jiffies'
/usr/src/linux/vmlinux.o:/usr/src/linux/kernel/printk.c:550: more
undefined references to `jiffies' follow
...
/usr/src/linux/vmlinux.o: In function `mem_init':
/usr/src/linux/arch/x86/mm/init_32.c:603: undefined reference to `_text'
/usr/src/linux/arch/x86/mm/init_32.c:605: undefined reference to `__init_end'
/usr/src/linux/arch/x86/mm/init_32.c:605: undefined reference to `__init_begin'
/usr/src/linux/arch/x86/mm/init_32.c:623: undefined reference to `_text'
/usr/src/linux/arch/x86/mm/init_32.c:623: undefined reference to `__init_end'
/usr/src/linux/arch/x86/mm/init_32.c:623: undefined reference to `__init_begin'
/usr/src/linux/vmlinux.o: In function `is_kernel_text':
/usr/src/linux/arch/x86/mm/init_32.c:147: undefined reference to `__init_end'
/usr/src/linux/arch/x86/mm/init_32.c:147: undefined reference to `__init_end'
/usr/src/linux/vmlinux.o: In function `kernel_physical_mapping_init':
/usr/src/linux/arch/x86/mm/init_32.c:207: undefined reference to `__init_end'
/usr/src/linux/vmlinux.o: In function `page_writeback_init':
/usr/src/linux/mm/page-writeback.c:773: undefined reference to `jiffies'
...

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: linux object file containing all kernel symbols and suitable for userspace linking?
  2008-09-28  7:22   ` Daniel Rosenthal
@ 2008-09-28 14:06     ` Jeff Dike
  2008-09-29  6:18       ` Daniel Rosenthal
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff Dike @ 2008-09-28 14:06 UTC (permalink / raw)
  To: Daniel Rosenthal; +Cc: LKML

On Sun, Sep 28, 2008 at 03:22:48AM -0400, Daniel Rosenthal wrote:
> It's looks close, but it seems to be missing some symbols.  Below is
> an excerpt of some of the some of the error messages that come up when
> trying to link vmlinux.o to another object file.  It looks like all
> the binary layout related symbols are missing, and jiffies also.
> How/when are these symbols normally linked into the final kernel
> image?

These are proided by the linker script.

      	  	     Jeff

-- 
Work email - jdike at linux dot intel dot com

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: linux object file containing all kernel symbols and suitable for userspace linking?
  2008-09-28 14:06     ` Jeff Dike
@ 2008-09-29  6:18       ` Daniel Rosenthal
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Rosenthal @ 2008-09-29  6:18 UTC (permalink / raw)
  To: Jeff Dike; +Cc: LKML

> These are provided by the linker script.

Ok, I took a look at both vmlinux_32.lds.S and uml.lds.S (I'm assuming
these are the linker scripts).  I also took a look at vmlinux.  I
didn't realize at first that vmlinux actually has some symbols in it.
I linked vmlinux to my programs using gcc and it compiled, but I got a
segmentation fault when I ran it.  What is the appropriate binary
format to use to output the kernel binary so it won't segfault in
userspace?  Ideally, I would like to add another target, say
vmlinux-user, that would output the kernel with all the same symbols
that vmlinux contains, but with a binary format suitable for userspace
linkage.  It looks from uml.lds.S that you don't use the default ELF
output format for UML.  Why is this?

I guess I probably need to write another architecture specific *.lds.S
file called something like vmlinux-user.lds.S and add a few lines to
the Makefile in the root directory to achieve what I am trying to do,
but I would like to find as general a solution as I can so that maybe
other architectures and other people can use the same solution for
doing kernel code unit tests without replicating a lot of code.

By the way, I noticed that you only have a single uml.lds.S file, and
consequently UML probably either only works on x86 (and x86-64), or
uses the same binary layout on all platforms.  I couldn't find
anywhere explicitly where you say UML only runs on x86, but just to
clarify, UML is x86 specific, right?

Daniel


> Work email - jdike at linux dot intel dot com

Sorry, I misread the {addtoit,linux.intel} as {addtoit,linux,intel} in
arch/um/Makefile.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-09-29  6:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-28  2:57 linux object file containing all kernel symbols and suitable for userspace linking? Daniel Rosenthal
2008-09-28  3:13 ` Grant Coady
2008-09-28  7:22   ` Daniel Rosenthal
2008-09-28 14:06     ` Jeff Dike
2008-09-29  6:18       ` Daniel Rosenthal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox