SUNOS built (macro pb)

Librairie C++ de calcul formel/ C++ symbolic computation library

Modérateur : xcasadmin

frederic han
Messages : 1137
Inscription : dim. mai 20, 2007 7:09 am
Localisation : Paris
Contact :

SUNOS built (macro pb)

Message par frederic han » mer. janv. 31, 2018 10:34 am

Hello,
sage report a built error on SUNOS due to a macro conflict defined in this OS:

cf: https://trac.sagemath.org/ticket/24619

they suggest the following patch:

Code : Tout sélectionner

+Work around _ABS macro on SunOS
+
+See https://trac.sagemath.org/ticket/24619
+
+diff -ru a/src/rpn.h b/src/rpn.h
+--- a/src/rpn.h	2016-01-03 09:12:13.000000000 +0100
++++ b/src/rpn.h	2018-01-31 10:36:43.049921736 +0100
+@@ -24,6 +24,10 @@
+ #include <string>
+ #include <ctype.h>
+ 
++/* SunOS defines this as macro */
++#undef _ABS
++
++
+ #ifndef NO_NAMESPACE_GIAC
+ namespace giac {
+ #endif // ndef NO_NAMESPACE_GIAC

parisse
Messages : 5731
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: SUNOS built (macro pb)

Message par parisse » mer. janv. 31, 2018 6:36 pm

Ok!

frederic han
Messages : 1137
Inscription : dim. mai 20, 2007 7:09 am
Localisation : Paris
Contact :

Re: SUNOS built (macro pb)

Message par frederic han » jeu. févr. 01, 2018 10:00 am

En fait ce patch ne suffit pas il y a ensuite d'autres problemes:
as tu une idee?

Code : Tout sélectionner

libtool: compile:  g++ -DHAVE_CONFIG_H -I. -I.. -DIN_GIAC -I. -I.. -I. -I.. -I/datapool/jeroen/sage/local/include -g -O2 -m64 -O2 -g -D_XPG6 -fno-strict-aliasing -DGIAC_GENERIC_CONSTANTS -MT gen.lo -MD -MP -MF .deps/gen.Tpo -c gen.cc  -fPIC -DPIC -o .libs/gen.o
gen.cc: In function 'giac::gen giac::chartab2gen(char*&, const giac::context*)':
gen.cc:11206:38: error: 'alloca' was not declared in this scope
       char * scopy=(char *)alloca(l+2);

Code : Tout sélectionner

help.cc: In function 'int giac::dir_select(const dirent*)':
help.cc:936:12: error: 'const struct dirent' has no member named 'd_type'
     if (d->d_type==DT_DIR || equalposcomp(subdir_strings,s)){
            ^
help.cc:936:20: error: 'DT_DIR' was not declared in this scope
     if (d->d_type==DT_DIR || equalposcomp(subdir_strings,s)){

parisse
Messages : 5731
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: SUNOS built (macro pb)

Message par parisse » jeu. févr. 01, 2018 10:14 am

alloca devrait etre connu pourtant, c'est declare dans stdlib.h (donc inclus dans #include <cstdlib>), peut-etre faut-il mettre std::alloca? Ou bien #include <alloca.h>?
Pour help.cc, on peut tout simplement desactiver cette partie ligne 908 en ajoutant un defined correspondant a SunOS, de toutes facons ce n'est pas une plateforme tres importante!

frederic han
Messages : 1137
Inscription : dim. mai 20, 2007 7:09 am
Localisation : Paris
Contact :

Re: SUNOS built (macro pb)

Message par frederic han » dim. févr. 04, 2018 10:10 pm

Les problemes semblent résolus dans sage:

les 3 patches appliqués sont la:

https://git.sagemath.org/sage.git/diff? ... 15930f202c

parisse
Messages : 5731
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: SUNOS built (macro pb)

Message par parisse » lun. févr. 05, 2018 7:03 am

Je ne peux pas back-porter ce genre de patches, d'abord il y a trop de risques d'en rater en les lisant avec un diff comme ca, il n'y aurait pas une UI ou on voit clairement les changements? Ensuite, il n'y a pas de commentaires sur les raisons des changements ni de recherche du changement minimal.
Par exemple, je vois qu'ils veulent modifier le prototype de

Code : Tout sélectionner

gen chartab2gen(char * & s,GIAC_CONTEXT);
en enlevant le &, or si j'ai mis un & c'est probablement que c'etait necessaire, au moins a un moment donne et pour une architecture donnee. Si ce n'est pas indispensable pour compiler pour sunos, pourquoi faire ce changement? Si c'est indispensable, alors ca devrait etre dans un ifdef specifique a sunos.
Pour l'introduction de DT_DIR, c'est la meme chose, qu'est-ce qui me garantit que ca va marcher sous windows et mac? Pourquoi ne pas avoir un ifdef specifique a sunos comme je le suggerais?
Le seul changement que je fais pour le moment (en plus de #undef ABS deja fait dans rpn.cc) c'est dans gen.cc pour alloca, changement que je reduis au minimum:

Code : Tout sélectionner

#if 1 // def FREERTOS
      ALLOCA(char, scopy, l+2); 
#else
      char * scopy=(char *)alloca(l+2);
#endif

parisse
Messages : 5731
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: SUNOS built (macro pb)

Message par parisse » lun. févr. 05, 2018 7:13 am

Bon, en regardant de plus pres help.cc, pour DT_DIR je fais les changements suivants qui me semblent beaucoup moins impactant et devraient passer sur sunos:

Code : Tout sélectionner

909c909
diff help.cc help.cc~
< #if defined WIN32 || !defined DT_DIR
---
> #ifdef WIN32
991c991
< #if defined WIN32 || !defined DT_DIR
---
> #ifdef WIN32

parisse
Messages : 5731
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: SUNOS built (macro pb)

Message par parisse » mer. févr. 07, 2018 12:50 pm

Bon, en retestant, je vois qu'il est en effet necessaire d'enlever le & du prototype de chartab2gen, a cause de la macro ALLOCA visiblement.

dimpase
Messages : 26
Inscription : mer. oct. 24, 2018 9:58 am

Re: SUNOS built (macro pb)

Message par dimpase » jeu. févr. 18, 2021 10:18 am

alloca issue on Solaris has not completely gone away (this is SPARC Solaris 11, gcc 10.2, giac 1.5.0.87)

Code : Tout sélectionner

/usr/bin/bash ../libtool  --tag=CXX   --mode=compile g++ -std=gnu++11 -DHAVE_CONFIG_H -I. -I..  -DIN_GIAC -I. -I.. -I. -I..     -I/datapool/dima/Sage/sage/local/include   -g -O2 -I/opt/csw/include -I/opt/csw/include/ncurses -fno-strict-aliasing -DGIAC_GENERIC_CONSTANTS -c -o quater.lo quater.cc
libtool: compile:  g++ -std=gnu++11 -DHAVE_CONFIG_H -I. -I.. -DIN_GIAC -I. -I.. -I. -I.. -I/datapool/dima/Sage/sage/local/include -g -O2 -I/opt/csw/include -I/opt/csw/include/ncurses -fno-strict-aliasing -DGIAC_GENERIC_CONSTANTS -c quater.cc  -fPIC -DPIC -o .libs/quater.o
threaded.cc: In function 'bool giac::mod_gcd(const std::vector<giac::T_unsigned<int, long long unsigned int> >&, const std::vector<giac::T_unsigned<int, long long unsigned int> >&, int, std::vector<giac::T_unsigned<int, long long unsigned int> >&, std::vector<giac::T_unsigned<int, long long unsigned int> >&, std::vector<giac::T_unsigned<int, long long unsigned int> >&, const std::vector<long long unsigned int>&, bool, bool, bool&, std::vector<std::vector<int> >&, std::vector<std::vector<int> >&, std::vector<std::vector<int> >&, std::vector<std::vector<int> >&, std::vector<std::vector<int> >&, std::vector<std::vector<int> >&, std::vector<std::vector<int> >&, int)':
threaded.cc:2960:69: error: 'alloca' was not declared in this scope; did you mean 'valloc'?
 2960 |       gcd_call_param<int> * gcd_call_param_v=(gcd_call_param<int> *)alloca(nthreads*sizeof(gcd_call_param<int>));
      |                                                                     ^~~~~~
      |                                                                     valloc
(yes, we still get requests for Solaris support...)

dimpase
Messages : 26
Inscription : mer. oct. 24, 2018 9:58 am

Re: SUNOS built (macro pb)

Message par dimpase » jeu. févr. 18, 2021 10:32 am

By the way, alloca is not standard C++ (or even C), it's machine/compiler-dependent, why does giac use it at all?
What is it that cannot be achieved with the usual C/C++ tools?

dimpase
Messages : 26
Inscription : mer. oct. 24, 2018 9:58 am

Re: SUNOS built (macro pb)

Message par dimpase » ven. févr. 19, 2021 9:12 am

Solaris has alloca() in a special header alloca.h

Adding `#include <alloca.h>` into `gen.cc` and `threaded.cc`
allows one to proceed.

parisse
Messages : 5731
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: SUNOS built (macro pb)

Message par parisse » sam. févr. 20, 2021 12:39 pm

dimpase a écrit :
jeu. févr. 18, 2021 10:32 am
By the way, alloca is not standard C++ (or even C), it's machine/compiler-dependent, why does giac use it at all?
What is it that cannot be achieved with the usual C/C++ tools?
alloca has two advantages for small memory allocations: it's faster than malloc and it does not require a matching free.

dimpase
Messages : 26
Inscription : mer. oct. 24, 2018 9:58 am

Re: SUNOS built (macro pb)

Message par dimpase » sam. févr. 20, 2021 6:43 pm

Why not just the default C++ allocator? My understanding is that it's faster than the usual system malloc (in the usual implementations).

Anyhow, there is AC_FUNC_ALLOCA which allows you to test for alloca.h header and set up HAVE_ALLOCA_H
so that you can do

#ifdef HAVE_ALLOCA_H
# include <alloca.h>
#endif

in the appropriate header, see
https://www.gnu.org/software/autoconf/m ... tions.html

parisse
Messages : 5731
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: SUNOS built (macro pb)

Message par parisse » sam. févr. 20, 2021 9:37 pm

I don't know what you mean by the default C++ allocator, if it's new or if it allocates memory on the heap, then it's slower than allocating on the stack.

I don't know why, but HAVE_ALLOCA_H is already defined in config.h. I will add in gen.h:

Code : Tout sélectionner

#ifdef HAVE_ALLOCA_H
#include <alloca.h>
#endif

dimpase
Messages : 26
Inscription : mer. oct. 24, 2018 9:58 am

Re: SUNOS built (macro pb)

Message par dimpase » dim. févr. 21, 2021 11:34 am

another problem on Solaris is the name clash with module_info on giac. (Solaris has module_info in /usr/include/sys/stream.h)

Code : Tout sélectionner

...
[giac-1.6.0.47p2] In file included from /usr/include/netinet/in.h:66,
[giac-1.6.0.47p2]                  from /usr/include/sys/socket.h:32,
[giac-1.6.0.47p2]                  from /usr/include/curl/system.h:436,
[giac-1.6.0.47p2]                  from /usr/include/curl/curl.h:38,
[giac-1.6.0.47p2]                  from misc.cc:9996:
[giac-1.6.0.47p2] /usr/include/sys/stream.h:221:8: error: redefinition of 'struct giac::module_info'
[giac-1.6.0.47p2]   221 | struct module_info {
[giac-1.6.0.47p2]       |        ^~~~~~~~~~~
...
A straightforward fix is to rename all giac's module_info, perhaps there is a more intelligent way using namespaces though.

Répondre