[Pkg-libvirt-maintainers] Bug#809185: [Libguestfs] Note regarding bin2s.pl

Richard W.M. Jones rjones at redhat.com
Tue Jan 12 11:10:20 UTC 2016


On Tue, Jan 12, 2016 at 10:05:00AM +0000, Richard W.M. Jones wrote:
> On Tue, Jan 12, 2016 at 07:57:03AM +0100, Hilko Bengen wrote:
> > Helge,
> > 
> > I have applied all the architecture-specific bits but not the bin2s
> > script yet. TBH, so far I don't see what is wrong about export and use
> > of the "_binary_init_size" constant.
> 
> [https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=809185]
> 
> I see it as a reasonable simplification - it allows us to get rid of
> that conditional code for HP-UX in bin2s.pl.
> 
> However looking at the patch, I don't like the casts in:
> 
> -  size_t n = (size_t) &_binary_init_size;
> +  size_t n = ((size_t) &_binary_init_end) - ((size_t) &_binary_init_start);
> 
> Since those are pointers, it seems better to simply subtract them.
> (Though it would be better if we'd declared the type of
> _binary_init_start/_end as uint8_t instead of char.)
> 
> If we must cast them then the correct integer to use is 'intptr_t', an
> int type that's guaranteed by C99 to be long enough to store a
> pointer.

How about the attached patch?

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/
-------------- next part --------------
>From 7cff794d82076df70dde7a851937fc7bf93fdf44 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones at redhat.com>
Date: Tue, 12 Jan 2016 11:07:57 +0000
Subject: [PATCH] bin2s: Remove _size, since it can be computed from _start and
 _end.

Also declare the _start and _end as uint8_t instead of char, since
they refer to an array of bytes.

See discussion here:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=809185
---
 src/bin2s.pl     | 8 --------
 src/ext2init-c.c | 5 +++--
 2 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/src/bin2s.pl b/src/bin2s.pl
index db6db26..8558126 100755
--- a/src/bin2s.pl
+++ b/src/bin2s.pl
@@ -39,7 +39,6 @@ print $ofh <<"EOF";
 
 \t.globl\t_binary_${infile}_start
 \t.globl\t_binary_${infile}_end
-\t.globl\t_binary_${infile}_size
 
 \t.section\t.rodata
 _binary_${infile}_start:
@@ -55,14 +54,7 @@ die "read $infile (at offset $sz): $!\n" if not defined $i;
 close $ifh;
 
 print $ofh <<"EOF";
-
 _binary_${infile}_end:
-
-#if defined(__hppa__)
-\t_binary_${infile}_size: .equ $sz
-#else
-\t.equ _binary_${infile}_size, $sz
-#endif
 EOF
 
 close $ofh;
diff --git a/src/ext2init-c.c b/src/ext2init-c.c
index c310ed2..66ad254 100644
--- a/src/ext2init-c.c
+++ b/src/ext2init-c.c
@@ -20,6 +20,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdint.h>
 #include <string.h>
 
 #include <caml/alloc.h>
@@ -28,14 +29,14 @@
 /* The init binary.
  * See: bin2s.pl, init.c.
  */
-extern char _binary_init_start, _binary_init_end, _binary_init_size;
+extern uint8_t _binary_init_start, _binary_init_end;
 
 value
 supermin_binary_init (value unitv)
 {
   CAMLparam1 (unitv);
   CAMLlocal1 (sv);
-  size_t n = (size_t) &_binary_init_size;
+  size_t n = &_binary_init_end - &_binary_init_start;
 
   sv = caml_alloc_string (n);
   memcpy (String_val (sv), &_binary_init_start, n);
-- 
2.5.0



More information about the Pkg-libvirt-maintainers mailing list