Skip to content
Browse files

make sure there is a null byte at end of the kernel bitcode since it'…

…s required by earlier versions of MemoryBuffer::getMemBuffer (patch by Thibault)

git-svn-id: http://svn.macosforge.org/repository/ruby/MacRuby/trunk@4140 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information...
1 parent 24896f9 commit 49a913ccb1a25bbc97ed6891fa537fd5757b390d Laurent Sansonetti committed May 24, 2010
Showing with 8 additions and 2 deletions.
  1. +4 −0 rakelib/builder.rake
  2. +4 −2 vm.cpp
View
4 rakelib/builder.rake
@@ -42,8 +42,12 @@ task :objects => [:config_h, :dtrace_h, :revision_h, :mark_gc] do
includes = CFLAGS.scan(/-I[^\s]+/).join(' ')
ARCHS.each do |x|
output = "kernel-#{x}.bc"
+ # Compile the IR for the kernel.c source file & optimize it.
sh "#{llvm_gcc} -arch #{x} -fexceptions #{includes} --emit-llvm -c kernel.c -o #{output}"
sh "#{opt} -O3 #{output} -o=#{output}"
+ # Convert the bitcode into a C static array. We append a null byte to the bitcode file because
+ # xxd doesn't, and it's needed by the bitcode reader later at runtime.
+ sh "/bin/dd if=/dev/zero count=1 bs=1 conv=notrunc >> #{output} 2>/dev/null"
sh "/usr/bin/xxd -i #{output} >> kernel_data.c"
sh "/bin/rm #{output}"
end
View
6 vm.cpp
@@ -4621,14 +4621,16 @@ Init_PreVM(void)
// To not corrupt stack pointer (essential for backtracing).
llvm::NoFramePointerElim = true;
+ // Retrieve the kernel bitcode for the right architecture. We substract
+ // 1 to the length because it's NULL terminated.
const char *kernel_beg;
const char *kernel_end;
#if __LP64__
kernel_beg = (const char *)kernel_x86_64_bc;
- kernel_end = kernel_beg + kernel_x86_64_bc_len;
+ kernel_end = kernel_beg + kernel_x86_64_bc_len - 1;
#else
kernel_beg = (const char *)kernel_i386_bc;
- kernel_end = kernel_beg + kernel_i386_bc_len;
+ kernel_end = kernel_beg + kernel_i386_bc_len - 1;
#endif
MemoryBuffer *mbuf = MemoryBuffer::getMemBuffer(kernel_beg, kernel_end);

0 comments on commit 49a913c

Please sign in to comment.
Something went wrong with that request. Please try again.