diff mbox

[1/2] daemon: Fix '--version'.

Message ID 87fupvx83x.fsf@gmail.com
State New
Headers show

Commit Message

Alex Vong Aug. 24, 2016, 1:34 a.m. UTC
Hi guixes,

This one and the next patch fix '--version' of guix-daemon and
guix-register. Currently, they are not working, which is the reason why
help2man gives error when building from source.

Comments

Alex Vong Aug. 29, 2016, 1:31 a.m. UTC | #1
Hi,

Alex Vong <alexvong1995@gmail.com> writes:

> Hi guixes,
>
> This one and the next patch fix '--version' of guix-daemon and
> guix-register. Currently, they are not working, which is the reason why
> help2man gives error when building from source.
>
>
> From 06d97b6de29aedeec7efe6f9a1e654145183a06b Mon Sep 17 00:00:00 2001
> From: Alex Vong <alexvong1995@gmail.com>
> Date: Wed, 24 Aug 2016 08:25:48 +0800
> Subject: [PATCH 1/2] daemon: Fix '--version'.
>
> * nix/nix-daemon/guix-daemon.cc (argp_program_version): Assigning
>   instead of declaring.
>   (argp_program_bug_address): Likewise.
> ---
>  nix/nix-daemon/guix-daemon.cc | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/nix/nix-daemon/guix-daemon.cc b/nix/nix-daemon/guix-daemon.cc
> index d5d33a5..41b56cb 100644
> --- a/nix/nix-daemon/guix-daemon.cc
> +++ b/nix/nix-daemon/guix-daemon.cc
> @@ -1,5 +1,6 @@
>  /* GNU Guix --- Functional package management for GNU
>     Copyright (C) 2012, 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
> +   Copyright (C) 2016 Alex Vong <alexvong1995@gmail.com>
>  
>     This file is part of GNU Guix.
>  
> @@ -53,10 +54,6 @@ extern void run (Strings args);
>  static const char guix_textdomain[] = "guix";
>  
>  
> -const char *argp_program_version =
> -  "guix-daemon (" PACKAGE_NAME ") " PACKAGE_VERSION;
> -const char *argp_program_bug_address = PACKAGE_BUGREPORT;
> -
>  static char doc[] =
>    n_("guix-daemon -- perform derivation builds and store accesses")
>    "\v\n"
> @@ -344,6 +341,8 @@ main (int argc, char *argv[])
>        settings.useBuildHook = false;
>  #endif
>  
> +      argp_program_version = "guix-daemon (" PACKAGE_NAME ") " PACKAGE_VERSION;
> +      argp_program_bug_address = PACKAGE_BUGREPORT;
>        argp_parse (&argp, argc, argv, 0, 0, 0);
>  
>        /* Effect all the changes made via 'settings.set'.  */

This patch and the other one fix the problem reported in
<https://lists.gnu.org/archive/html/guix-devel/2016-08/msg00529.html>,
do they look good?

Thanks,
Alex
Ludovic Courtès Aug. 29, 2016, 4:12 p.m. UTC | #2
Hi!

Alex Vong <alexvong1995@gmail.com> skribis:

> This one and the next patch fix '--version' of guix-daemon and
> guix-register. Currently, they are not working, which is the reason why
> help2man gives error when building from source.

How are they not working exactly?  :-)

It definitely works for me:

--8<---------------cut here---------------start------------->8---
$ ./guix-daemon --version
guix-daemon (GNU Guix) 0.11.0
$ ./guix-register --version
guix-register (GNU Guix) 0.11.0
--8<---------------cut here---------------end--------------->8---

Ludo’.
Alex Vong Aug. 30, 2016, 4:29 a.m. UTC | #3
Hello,

ludo@gnu.org (Ludovic Courtès) writes:

> Hi!
>
> Alex Vong <alexvong1995@gmail.com> skribis:
>
>> This one and the next patch fix '--version' of guix-daemon and
>> guix-register. Currently, they are not working, which is the reason why
>> help2man gives error when building from source.
>
> How are they not working exactly?  :-)
>
> It definitely works for me:
>
> $ ./guix-daemon --version
> guix-daemon (GNU Guix) 0.11.0
> $ ./guix-register --version
> guix-register (GNU Guix) 0.11.0
>
I get this output instead:

$ LC_ALL=C ./guix-daemon --version
./guix-daemon: unrecognized option '--version'
Try `guix-daemon --help' or `guix-daemon --usage' for more information.

This is werid, but I think it is because I build guix with lto.

Here is how I build guix:

$ ./bootstrap && ./configure CFLAGS='-O2 -flto' CXXFLAGS='-O2 -flto' LDFLAGS='-O2 -flto' && make -j`nproc` AR=gcc-ar NM=gcc-nm RANLIB=gcc-ranlib

So, perhaps this is a gcc bug! (not guix's one, we can forget about the
patch)

Could you reproduce it?

> Ludo’.

Thanks,
Alex
Ludovic Courtès Aug. 31, 2016, 9:13 p.m. UTC | #4
Hi Alex,

Alex Vong <alexvong1995@gmail.com> skribis:

> ludo@gnu.org (Ludovic Courtès) writes:
>
>> Hi!
>>
>> Alex Vong <alexvong1995@gmail.com> skribis:
>>
>>> This one and the next patch fix '--version' of guix-daemon and
>>> guix-register. Currently, they are not working, which is the reason why
>>> help2man gives error when building from source.

[...]

> I get this output instead:
>
> $ LC_ALL=C ./guix-daemon --version
> ./guix-daemon: unrecognized option '--version'
> Try `guix-daemon --help' or `guix-daemon --usage' for more information.
>
> This is werid, but I think it is because I build guix with lto.

What about the attached program?  It works for me with GCC 6.2.0, both
with and without LTO.

Ludo’.
#include <argp.h>

const char *argp_program_version = "foo";
const char *argp_program_bug_address = "foo@example.org";

static const struct argp_option options[] =
  {
    { "system", 's', "SYSTEM", 0,
      "assume SYSTEM as the current system type" },
    { 0, 0, 0, 0, 0 }
  };

static const struct argp argp =
  {
    options, NULL,
    NULL, "doc",
    NULL, NULL,
    NULL
  };

int
main (int argc, char *argv[])
{
  argp_parse (&argp, argc, argv, 0, 0, 0);
  return 0;
}
Alex Vong Sept. 1, 2016, 6:23 a.m. UTC | #5
Hi Ludovic,

ludo@gnu.org (Ludovic Courtès) writes:

> Hi Alex,
>
> Alex Vong <alexvong1995@gmail.com> skribis:
>
[...]
>
>> I get this output instead:
>>
>> $ LC_ALL=C ./guix-daemon --version
>> ./guix-daemon: unrecognized option '--version'
>> Try `guix-daemon --help' or `guix-daemon --usage' for more information.
>>
>> This is werid, but I think it is because I build guix with lto.
>
> What about the attached program?  It works for me with GCC 6.2.0, both
> with and without LTO.
>
> Ludo’.
>
> #include <argp.h>
>
> const char *argp_program_version = "foo";
> const char *argp_program_bug_address = "foo@example.org";
>
> static const struct argp_option options[] =
>   {
>     { "system", 's', "SYSTEM", 0,
>       "assume SYSTEM as the current system type" },
>     { 0, 0, 0, 0, 0 }
>   };
>
> static const struct argp argp =
>   {
>     options, NULL,
>     NULL, "doc",
>     NULL, NULL,
>     NULL
>   };
>
> int
> main (int argc, char *argv[])
> {
>   argp_parse (&argp, argc, argv, 0, 0, 0);
>   return 0;
> }

I think you have isolated the problem! This test case does not work for
me.


I get the following output after building with
(g++ -O2 -flto version.cxx):
==============================================================================
alexvong1995@debian:~/c++$ ./a.out --version
./a.out: unrecognized option '--version'
Try `a.out --help' or `a.out --usage' for more information.
===========================================================================
alexvong1995@debian:~/c++$ ./a.out --help
Usage: a.out [OPTION...]
doc

  -s, --system=SYSTEM        assume SYSTEM as the current system type
  -?, --help                 Give this help list
      --usage                Give a short usage message

Mandatory or optional arguments to long options are also mandatory or optional
for any corresponding short options.
===========================================================================


My gcc version is also 6.2.0:
===========================================================================
alexvong1995@debian:~/c++$ LC_ALL=C g++ --version
g++ (GCC) 6.2.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

===========================================================================


Running strace show the following output
(ltrace output is not intersting):
===========================================================================
alexvong1995@debian:~/c++$ strace ./a.out --version
execve("./a.out", ["./a.out", "--version"], [/* 71 vars */]) = 0
brk(0)                                  = 0xf63000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc8f6b26000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/gnu/store/m9vxvhdj691bq1f85lpflvnhcvrdilih-glibc-2.23/lib/tls/x86_64/libstdc++.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/gnu/store/m9vxvhdj691bq1f85lpflvnhcvrdilih-glibc-2.23/lib/tls/x86_64", 0x7fff93fa35f0) = -1 ENOENT (No such file or directory)
open("/gnu/store/m9vxvhdj691bq1f85lpflvnhcvrdilih-glibc-2.23/lib/tls/libstdc++.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/gnu/store/m9vxvhdj691bq1f85lpflvnhcvrdilih-glibc-2.23/lib/tls", 0x7fff93fa35f0) = -1 ENOENT (No such file or directory)
open("/gnu/store/m9vxvhdj691bq1f85lpflvnhcvrdilih-glibc-2.23/lib/x86_64/libstdc++.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/gnu/store/m9vxvhdj691bq1f85lpflvnhcvrdilih-glibc-2.23/lib/x86_64", 0x7fff93fa35f0) = -1 ENOENT (No such file or directory)
open("/gnu/store/m9vxvhdj691bq1f85lpflvnhcvrdilih-glibc-2.23/lib/libstdc++.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/gnu/store/m9vxvhdj691bq1f85lpflvnhcvrdilih-glibc-2.23/lib", {st_mode=S_IFDIR|0555, st_size=4096, ...}) = 0
open("/gnu/store/v9r00bv3ivimpr0nzhaas3rsqaa5xvbw-gcc-6.2.0-lib/lib/tls/x86_64/libstdc++.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/gnu/store/v9r00bv3ivimpr0nzhaas3rsqaa5xvbw-gcc-6.2.0-lib/lib/tls/x86_64", 0x7fff93fa35f0) = -1 ENOENT (No such file or directory)
open("/gnu/store/v9r00bv3ivimpr0nzhaas3rsqaa5xvbw-gcc-6.2.0-lib/lib/tls/libstdc++.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/gnu/store/v9r00bv3ivimpr0nzhaas3rsqaa5xvbw-gcc-6.2.0-lib/lib/tls", 0x7fff93fa35f0) = -1 ENOENT (No such file or directory)
open("/gnu/store/v9r00bv3ivimpr0nzhaas3rsqaa5xvbw-gcc-6.2.0-lib/lib/x86_64/libstdc++.so.6", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
stat("/gnu/store/v9r00bv3ivimpr0nzhaas3rsqaa5xvbw-gcc-6.2.0-lib/lib/x86_64", 0x7fff93fa35f0) = -1 ENOENT (No such file or directory)
open("/gnu/store/v9r00bv3ivimpr0nzhaas3rsqaa5xvbw-gcc-6.2.0-lib/lib/libstdc++.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\20\255\10\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0555, st_size=2032024, ...}) = 0
mmap(NULL, 3666688, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc8f6586000
mprotect(0x7fc8f66f7000, 2093056, PROT_NONE) = 0
mmap(0x7fc8f68f6000, 49152, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x170000) = 0x7fc8f68f6000
mmap(0x7fc8f6902000, 13056, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fc8f6902000
close(3)                                = 0
open("/gnu/store/m9vxvhdj691bq1f85lpflvnhcvrdilih-glibc-2.23/lib/libm.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0`U\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0555, st_size=1141048, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc8f6b25000
mmap(NULL, 3166528, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc8f6280000
mprotect(0x7fc8f6385000, 2093056, PROT_NONE) = 0
mmap(0x7fc8f6584000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x104000) = 0x7fc8f6584000
close(3)                                = 0
open("/gnu/store/m9vxvhdj691bq1f85lpflvnhcvrdilih-glibc-2.23/lib/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)
open("/gnu/store/v9r00bv3ivimpr0nzhaas3rsqaa5xvbw-gcc-6.2.0-lib/lib/libgcc_s.so.1", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0p*\0\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0444, st_size=100680, ...}) = 0
mmap(NULL, 2185584, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc8f606a000
mprotect(0x7fc8f6080000, 2093056, PROT_NONE) = 0
mmap(0x7fc8f627f000, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x15000) = 0x7fc8f627f000
close(3)                                = 0
open("/gnu/store/m9vxvhdj691bq1f85lpflvnhcvrdilih-glibc-2.23/lib/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0 \t\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0555, st_size=1942128, ...}) = 0
mmap(NULL, 3808896, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fc8f5cc8000
mprotect(0x7fc8f5e61000, 2093056, PROT_NONE) = 0
mmap(0x7fc8f6060000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x198000) = 0x7fc8f6060000
mmap(0x7fc8f6066000, 16000, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fc8f6066000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc8f6b24000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc8f6b22000
arch_prctl(ARCH_SET_FS, 0x7fc8f6b22740) = 0
mprotect(0x7fc8f6060000, 16384, PROT_READ) = 0
mprotect(0x7fc8f6584000, 4096, PROT_READ) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fc8f6b21000
mprotect(0x7fc8f68f6000, 40960, PROT_READ) = 0
mprotect(0x7fc8f6b28000, 4096, PROT_READ) = 0
brk(0)                                  = 0xf63000
brk(0xf95000)                           = 0xf95000
write(2, "./a.out: unrecognized option '--"..., 41./a.out: unrecognized option '--version'
) = 41
write(2, "Try `a.out --help' or `a.out --u"..., 60Try `a.out --help' or `a.out --usage' for more information.
) = 60
exit_group(64)                          = ?
+++ exited with 64 +++
===========================================================================


Do you have any idea?


Thanks,
Alex
Ludovic Courtès Sept. 1, 2016, 12:15 p.m. UTC | #6
Alex Vong <alexvong1995@gmail.com> skribis:

> ludo@gnu.org (Ludovic Courtès) writes:

[...]

>> #include <argp.h>
>>
>> const char *argp_program_version = "foo";
>> const char *argp_program_bug_address = "foo@example.org";
>>
>> static const struct argp_option options[] =
>>   {
>>     { "system", 's', "SYSTEM", 0,
>>       "assume SYSTEM as the current system type" },
>>     { 0, 0, 0, 0, 0 }
>>   };
>>
>> static const struct argp argp =
>>   {
>>     options, NULL,
>>     NULL, "doc",
>>     NULL, NULL,
>>     NULL
>>   };
>>
>> int
>> main (int argc, char *argv[])
>> {
>>   argp_parse (&argp, argc, argv, 0, 0, 0);
>>   return 0;
>> }
>
> I think you have isolated the problem! This test case does not work for
> me.
>
>
> I get the following output after building with
> (g++ -O2 -flto version.cxx):

What if you compile with ‘gcc’ (and rename to foo.c) instead of ‘g++’?

It might be a symbol visibility problem, or name mangling issue.

Ludo’.
Alex Vong Sept. 2, 2016, 1 a.m. UTC | #7
ludo@gnu.org (Ludovic Courtès) writes:

> Alex Vong <alexvong1995@gmail.com> skribis:
>
[...]
>>
>> I think you have isolated the problem! This test case does not work for
>> me.
>>
>>
>> I get the following output after building with
>> (g++ -O2 -flto version.cxx):
>
> What if you compile with ‘gcc’ (and rename to foo.c) instead of ‘g++’?
>
> It might be a symbol visibility problem, or name mangling issue.
>
> Ludo’.

Hmm, I try to build with 'gcc -O2 -flto version.c' and './a.out
--version' still fails with 'unrecognized option'. I check the symbols
using 'nm' and they are not mangled. How should I check for the sign of
a symbol visibility problems? 

Thanks,
Alex
Ludovic Courtès Sept. 2, 2016, 12:41 p.m. UTC | #8
Alex Vong <alexvong1995@gmail.com> skribis:

> ludo@gnu.org (Ludovic Courtès) writes:
>
>> Alex Vong <alexvong1995@gmail.com> skribis:
>>
> [...]
>>>
>>> I think you have isolated the problem! This test case does not work for
>>> me.
>>>
>>>
>>> I get the following output after building with
>>> (g++ -O2 -flto version.cxx):
>>
>> What if you compile with ‘gcc’ (and rename to foo.c) instead of ‘g++’?
>>
>> It might be a symbol visibility problem, or name mangling issue.
>>
>> Ludo’.
>
> Hmm, I try to build with 'gcc -O2 -flto version.c' and './a.out
> --version' still fails with 'unrecognized option'. I check the symbols
> using 'nm' and they are not mangled. How should I check for the sign of
> a symbol visibility problems? 

‘nm’ shows a capital T for exported symbols, and a lowercase t for
hidden/private symbols.

Maybe you should report a bug against your distro’s package and see what
they think?

Ludo’.
diff mbox

Patch

From 06d97b6de29aedeec7efe6f9a1e654145183a06b Mon Sep 17 00:00:00 2001
From: Alex Vong <alexvong1995@gmail.com>
Date: Wed, 24 Aug 2016 08:25:48 +0800
Subject: [PATCH 1/2] daemon: Fix '--version'.

* nix/nix-daemon/guix-daemon.cc (argp_program_version): Assigning
  instead of declaring.
  (argp_program_bug_address): Likewise.
---
 nix/nix-daemon/guix-daemon.cc | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/nix/nix-daemon/guix-daemon.cc b/nix/nix-daemon/guix-daemon.cc
index d5d33a5..41b56cb 100644
--- a/nix/nix-daemon/guix-daemon.cc
+++ b/nix/nix-daemon/guix-daemon.cc
@@ -1,5 +1,6 @@ 
 /* GNU Guix --- Functional package management for GNU
    Copyright (C) 2012, 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
+   Copyright (C) 2016 Alex Vong <alexvong1995@gmail.com>
 
    This file is part of GNU Guix.
 
@@ -53,10 +54,6 @@  extern void run (Strings args);
 static const char guix_textdomain[] = "guix";
 
 
-const char *argp_program_version =
-  "guix-daemon (" PACKAGE_NAME ") " PACKAGE_VERSION;
-const char *argp_program_bug_address = PACKAGE_BUGREPORT;
-
 static char doc[] =
   n_("guix-daemon -- perform derivation builds and store accesses")
   "\v\n"
@@ -344,6 +341,8 @@  main (int argc, char *argv[])
       settings.useBuildHook = false;
 #endif
 
+      argp_program_version = "guix-daemon (" PACKAGE_NAME ") " PACKAGE_VERSION;
+      argp_program_bug_address = PACKAGE_BUGREPORT;
       argp_parse (&argp, argc, argv, 0, 0, 0);
 
       /* Effect all the changes made via 'settings.set'.  */
-- 
2.9.3