Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POSIX.pm does not guard against ctermid() being unavailable (as it is on Android 5+) #14715

Open
p5pRT opened this issue May 23, 2015 · 7 comments

Comments

@p5pRT
Copy link

p5pRT commented May 23, 2015

Migrated from rt.perl.org#125240 (status was 'open')

Searchable as RT125240$

@p5pRT
Copy link
Author

p5pRT commented May 23, 2015

From @Corion

Created by @Corion

This is a bug report for perl from corion@​cpan.org,
generated with the help of perlbug 1.40 running under perl 5.22.0.

-----------------------------------------------------------------

The Configure script probes for termios.h being available and
also probes for the C< ctermid() > function being available.
Perl is compiled accordingly, but POSIX.pm only has guards
against C< termios.h > not being available wholesale, but not
for C< termios.h > being available but C< ctermid() > not being
available. This is for example the case on Android 5
(Cyanogenmod 12 in this case). Android 4.4 seems to either
not have C< termios.h > at all or seems to implement
C< ctermid() >.

This leads to perl building but failing all tests that directly
or indirectly load POSIX.xs, because the dynamic reference
to ctermid() cannot be resolved.

The long term fix (5.23+) would be to add compile guards
around ctermid() and also pass the information from
Configure to POSIX.xs , possibly through d_ctermid .

The short term fix for 5.22 is to add a compile-time
check in the Android hints ( hints/linux-android.sh ) that
tries to compile a C program which uses ctermid() and
disables usage/presence of C< termios.h > alltogether
if compiling that program fails. The following lines
are my feeble attempt to create the appropriate CBU
in hints/linux-android.sh​:

$cat > try.c << 'EOM'
#include <termios.h>
int main() { (void) ctermid(0); return(0); }
EOM
$cc $ccflags try.c -o try
android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
if test "X$?" != X0; then
  # This should be respected by POSIX.xs, but isn't
  d_ctermid="$undef"
  # So we disable the whole of termios.h
  i_termios="$undef"
fi
if test "X$android_warn" != X; then
  # This should be respected by POSIX.xs, but isn't
  d_ctermid="$undef"
  # So we disable the whole of termios.h
  i_termios="$undef"
fi

-max

Perl Info

Flags:
     category=library
     severity=low
     module=POSIX

Site configuration information for perl 5.22.0:

Configured by unknown at Sat May 23 07:05:41 UTC 2015.

Summary of my perl5 (revision 5 version 22 subversion 0) configuration:

   Platform:
     osname=android, osvers=5.0.2, archname=armv7l-linux-android
     uname='linux localhost 3.10.33 #1 smp preempt fri apr 17 07:07:43 
cest 2015 armv7l gnulinux '
     config_args='-Duserelocatableinc -Dusedevel 
-Dprefix=/data/local/perl 
-Dsysroot=/data/data/com.pdaxrom.cctools/root/cctools 
-Alibpth=/system/lib /vendor/lib -Dman1dir=none -Dman3dir=none 
-Dsite1man=none -Dsite3man=none -Dvendorman1=none -Dvendorman3=none -des'
     hint=recommended, useposix=true, d_sigaction=define
     useithreads=undef, usemultiplicity=undef
     use64bitint=undef, use64bitall=undef, uselongdouble=undef
     usemymalloc=n, bincompat5005=undef
   Compiler:
     cc='cc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector 
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2',
     optimize='-O2',
     cppflags='-fno-strict-aliasing -pipe -fstack-protector'
     ccversion='', gccversion='4.8', gccosandvers=''
     intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234, 
doublekind=3
     d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8, 
longdblkind=0
     ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', 
lseeksize=4
     alignbytes=8, prototype=define
   Linker and Libraries:
     ld='cc', ldflags =' -L/system/lib -fstack-protector'
     libpth=/system/lib /vendor/lib 
/data/data/com.pdaxrom.cctools/root/cctools/bin/../lib/gcc/arm-linux-androideabi/4.8/include-fixed 
/data/data/com.pdaxrom.cctools/root/cctools/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/lib 
/data/data/com.pdaxrom.cctools/root/cctools/lib /system/lib /vendor/lib 
/system/lib /vendor/lib /system/lib /vendor/lib /system/lib /vendor/lib 
/system/lib /vendor/lib
     libs=-ldl -lm -lc
     perllibs=-ldl -lm -lc
     libc=/system/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
     gnulibc_version=''
   Dynamic Linking:
     dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
     cccdlflags='-fPIC 
--sysroot=/data/data/com.pdaxrom.cctools/root/cctools', 
lddlflags='-shared -O2 --sysroot 
/data/data/com.pdaxrom.cctools/root/cctools -L/system/lib -fstack-protector'

Locally applied patches:
     RC2


@INC for perl 5.22.0:
     lib
     ./../lib/site_perl/5.22.0/armv7l-linux-android
     ./../lib/site_perl/5.22.0
     ./../lib/5.22.0/armv7l-linux-android
     ./../lib/5.22.0
     .


Environment for perl 5.22.0:
     HOME=/
     LANG (unset)
     LANGUAGE (unset)
 
LD_LIBRARY_PATH=/data/data/com.pdaxrom.cctools/root/cctools/lib:/data/local/perl-5.22.0-RC2:/data/local/perl-5.22.0-RC2/lib:/data/local/perl-5.22.0-RC2/lib/auto:
     LOGDIR (unset)
 
PATH=/data/data/com.pdaxrom.cctools/root/cctools/sbin:/data/data/com.pdaxrom.cctools/root/cctools/bin:/system/xbin:/system/bin:/data/data/com.pdaxrom.cctools/root/cctools/bin:/data/data/com.pdaxrom.cctools/root/cctools/sbi
     PERL_BADLANG (unset)
     SHELL=/system/bin/sh

@p5pRT
Copy link
Author

p5pRT commented May 26, 2015

From @Corion

Hi all,

attached is the patch that I tested on Android 5 (Cyanogenmod 12) and
Android 4.4 (Cyanogenmod 11). It also still passed the tests on Windows.

I submit this patch for consideration for 5.22.0 - it marks termios.h as
unavailable on Android if ctermid() does not compile. The side-effect
for other platforms is non-existent and building on Android currently
doesn't pass all its tests.

If this patch doesn't make it into 5.22.0, it should go into the section
of known problems instead :-)

I'll look at patching POSIX.xs for 5.23 so it can use the detection
result(s) of Configure whether ctermid() exists and works.

-max

@p5pRT
Copy link
Author

p5pRT commented May 26, 2015

From @Corion

0001-Detect-in-Metaconfig-whether-termios.h-implements-a-.patch
From e8e24eca58d314c3701630ff85443d5fb01f4262 Mon Sep 17 00:00:00 2001
From: Max Maischein <corion@corion.net>
Date: Tue, 26 May 2015 21:28:43 +0200
Subject: [PATCH] Detect in Metaconfig whether termios.h implements a workable
 ctermid()

This is a stopgap measure to get POSIX.xs to work on Android 5, which
provides a termios.h file, but does not implement the ctermid()
function in its C library.

Without this patch, loading POSIX.so fails because the symbol ctermid()
cannot be resolved.

The longterm fix will be to have POSIX.xs check the functions
one by one instead of assuming they are all there if termios.h is there.
---
 hints/linux-android.sh | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/hints/linux-android.sh b/hints/linux-android.sh
index 6a59cb7..034f4fa 100644
--- a/hints/linux-android.sh
+++ b/hints/linux-android.sh
@@ -60,6 +60,25 @@ $cat > UU/archname.cbu <<'EOCBU'
 android_stub='FIX|Android'
 
 $cat > try.c << 'EOM'
+#include <termios.h>
+int main() { (void) ctermid(0); return(0); }
+EOM
+$cc $ccflags try.c -o try
+android_warn=`$run ./try 2>&1 | $egrep "$android_stub"`
+if test "X$?" != X0; then
+   # This should be respected by POSIX.xs, but isn't
+   d_ctermid="$undef"
+   # So we disable the whole of termios.h
+   i_termios="$undef"
+fi
+if test "X$android_warn" != X; then
+   # This should be respected by POSIX.xs, but isn't
+   d_ctermid="$undef"
+   # So we disable the whole of termios.h
+   i_termios="$undef"
+fi
+
+$cat > try.c << 'EOM'
 #include <netdb.h>
 int main() { (void) getnetbyname("foo"); return(0); }
 EOM
-- 
1.8.1.msysgit.1

@p5pRT
Copy link
Author

p5pRT commented May 26, 2015

From @Tux

On Tue, 26 May 2015 21​:50​:54 +0200, Max Maischein <corion@​cpan.org>
wrote​:

Hi all,

attached is the patch that I tested on Android 5 (Cyanogenmod 12) and
Android 4.4 (Cyanogenmod 11). It also still passed the tests on Windows.

I submit this patch for consideration for 5.22.0 - it marks termios.h as
unavailable on Android if ctermid() does not compile. The side-effect
for other platforms is non-existent and building on Android currently
doesn't pass all its tests.

If this patch doesn't make it into 5.22.0, it should go into the section
of known problems instead :-)

+1 for inclusion in 5.22

I'll look at patching POSIX.xs for 5.23 so it can use the detection
result(s) of Configure whether ctermid() exists and works.

-max

--
H.Merijn Brand http​://tux.nl Perl Monger http​://amsterdam.pm.org/
using perl5.00307 .. 5.21 porting perl5 on HP-UX, AIX, and openSUSE
http​://mirrors.develooper.com/hpux/ http​://www.test-smoke.org/
http​://qa.perl.org http​://www.goldmark.org/jeff/stupid-disclaimers/

@p5pRT
Copy link
Author

p5pRT commented May 26, 2015

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Sep 16, 2015

From @khwilliamson

On Tue May 26 13​:24​:31 2015, hmbrand wrote​:

On Tue, 26 May 2015 21​:50​:54 +0200, Max Maischein <corion@​cpan.org>
wrote​:

Hi all,

attached is the patch that I tested on Android 5 (Cyanogenmod 12) and
Android 4.4 (Cyanogenmod 11). It also still passed the tests on Windows.

I submit this patch for consideration for 5.22.0 - it marks termios.h as
unavailable on Android if ctermid() does not compile. The side-effect
for other platforms is non-existent and building on Android currently
doesn't pass all its tests.

If this patch doesn't make it into 5.22.0, it should go into the section
of known problems instead :-)

+1 for inclusion in 5.22

I'll look at patching POSIX.xs for 5.23 so it can use the detection
result(s) of Configure whether ctermid() exists and works.

-max

What should be done now about this ticket?
--
Karl Williamson

@p5pRT
Copy link
Author

p5pRT commented Sep 17, 2015

From @Corion

Hello Karl,

thank you for keeping track of the tickets!

attached is the patch that I tested on Android 5 (Cyanogenmod 12) and
Android 4.4 (Cyanogenmod 11). It also still passed the tests on Windows.

I submit this patch for consideration for 5.22.0 - it marks termios.h as
unavailable on Android if ctermid() does not compile. The side-effect
for other platforms is non-existent and building on Android currently
doesn't pass all its tests.

If this patch doesn't make it into 5.22.0, it should go into the section
of known problems instead :-)

+1 for inclusion in 5.22

I'll look at patching POSIX.xs for 5.23 so it can use the detection
result(s) of Configure whether ctermid() exists and works.

-max

What should be done now about this ticket?

I have talked to Merijn and I'm slowly (slowly!) getting my feel around
Metaconfig parts to find out how it would be possible to transport
information from ./Configure to POSIX.xs. But I don't expect this to be
a task that is quickly finished.

I've since found that there are many more idiosyncrasies between Android
(clib) versions so I expect many more tests to need to move from "does
this function exist in the header?" to "does a C program using this
function compile?" and "does a C program using this function compile and
return the proper result?". This will be a slow process.

-max

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants