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

Fails to link if libpng/jpeg development libraries are missing. #109

Open
Quipyowert2 opened this issue Aug 30, 2024 · 0 comments
Open

Fails to link if libpng/jpeg development libraries are missing. #109

Quipyowert2 opened this issue Aug 30, 2024 · 0 comments

Comments

@Quipyowert2
Copy link

Fails to link if libpng/jpeg development libraries are missing.

When compiling Tk 804.036, the following warning appears when configuring:
'pkg-config libpng' failed, continue with fallback values for cflags and libs...

This is because I have libpng16-devel installed which has libpng16.pc instead of plain libpng.pc. Because libpng was not found, the build system attempts to compile the bundled libpng. My brewed perl was compiled with _FORTIFY_SOURCE and -O2 and the build system picks up the _FORTIFY_SOURCE option, but ignores the optimization flag when compiling libpng/jpeg. This leads to the following warning when checking for <errno.h> in PNG/zlib/configure:405:

cc -c -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/inclu
de -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -o example test.c
In file included from /usr/include/errno.h:25,
                 from test.c:1:
/usr/include/features.h:414:4: warning: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Wcpp]
  414 | #  warning _FORTIFY_SOURCE requires compiling with optimization (-O)
      |    ^~~~~~~

As configure checks the compiler output against the empty string, it assumes that <errno.h> is not found, defining the NO_ERRNO_H macro. This leads to the errno global variable being declared in PNG/zlib/zutil.h:35. This non-thread local storage variable declaration clashes with the TLS definition in the version of glibc I have installed (which is 2.39), leading to the following error when linking:

> cc -fPIC -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -fPIC -DNO_snprintf -DHAS_sprintf_void -DNO_ERRNO_H -o example example.o -L. libz.a
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: errno: TLS definition in /lib64/libc.so.6 section .tbss mismatches non-TLS reference in libz.a(gzio.o)
/usr/lib64/gcc/x86_64-suse-linux/13/../../../../x86_64-suse-linux/bin/ld: /lib64/libc.so.6: error adding symbols: bad value

The fix is simple: Enable optimization by adding $Config{optimize} flag, which was -O2 on the Perl I brewed, to the CFLAGS for the bundled libpng and jpeg so that _FORTIFY_SOURCE, which was added to Perl's build system starting in 5.22, doesn't cause a warning.

diff --git a/JPEG/Makefile.jpeg.maybe b/JPEG/Makefile.jpeg.maybe
index 7bb9688b..063e53d3 100755
--- a/JPEG/Makefile.jpeg.maybe
+++ b/JPEG/Makefile.jpeg.maybe
@@ -32,7 +32,7 @@ if ($^O eq 'MSWin32')
 else
  {
   $ENV{CC} = $Config{cc};
-  local $ENV{CFLAGS} = "$Config{ccflags} $Config{cccdlflags}";
+  local $ENV{CFLAGS} = "$Config{ccflags} $Config{optimize} $Config{cccdlflags}";
   local $ENV{LDFLAGS} = "$Config{ccflags} $Config{ldflags}";
   system(sh => "./configure");
  }
diff --git a/PNG/Makefile.zlib.maybe b/PNG/Makefile.zlib.maybe
index 6da4ba9a..abe519b8 100644
--- a/PNG/Makefile.zlib.maybe
+++ b/PNG/Makefile.zlib.maybe
@@ -26,7 +26,7 @@ if ($^O eq 'MSWin32')
 else
  {
   $ENV{CC} = $Config{cc};
-  local $ENV{CFLAGS} = "$Config{ccflags} $Config{cccdlflags}";
+  local $ENV{CFLAGS} = "$Config{ccflags} $Config{optimize} $Config{cccdlflags}";
   system(sh => "./configure");
  }

VERSIONS

Perl 5.41.2 (installed from source with Perlbrew)
CPAN: 1.64
GCC 13.3.0 (official Tumbleweed package)
GLIBC 2.39 (official Tumbleweed package)
openSUSE Tumbleweed 20240725-0 (Last month's snapshot)
perl-Tk version: 804.036-18-gf0bb386b
libPNG: libpng16-16 libpng16-devel
libJPEG: libjpeg8 (don't have -devel package installed at the moment)
ld.bfd version: GNU ld (GNU Binutils; openSUSE Tumbleweed) 2.42.0.20240130-4
WSL2 version:

WSL version: 2.2.4.0
Kernel version: 5.15.153.1-2
WSLg version: 1.0.61
MSRDC version: 1.2.5326
Direct3D version: 1.611.1-81528511
DXCore version: 10.0.26091.1-240325-1447.ge-release
Windows version: 10.0.19045.4780
perl -V
Summary of my perl5 (revision 5 version 41 subversion 2) configuration:

  Platform:
    osname=linux
    osvers=5.15.153.1-microsoft-standard-wsl2
    archname=x86_64-linux
    uname='linux msi 5.15.153.1-microsoft-standard-wsl2 #1 smp fri mar 29 23:14:13 utc 2024 x86_64 x86_64 x86_64 gnulinux '
    config_args='-de -Dprefix=/home/nathan/perl5/perlbrew/perls/perl-5.41.2 -Dusedevel -Aeval:scriptdir=/home/nathan/perl5/perlbrew/perls/perl-5.41.2/bin'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
  Compiler:
    cc='cc'
    ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2'
    optimize='-O2'
    cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='13.3.0'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='off_t'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='cc'
    ldflags =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/x86_64-suse-linux/lib /usr/lib /usr/lib64 /usr/local/lib64
    libs=-lpthread -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -ldl -lm -lcrypt -lutil -lc
    libc=/lib/../lib64/libc.so.6
    so=so
    useshrplib=false
    libperl=libperl.a
    gnulibc_version='2.39'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector-strong'


Characteristics of this binary (from libperl):
  Compile-time options:
    HAS_LONG_DOUBLE
    HAS_STRTOLD
    HAS_TIMES
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_HASH_FUNC_SIPHASH13
    PERL_HASH_USE_SBOX32
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    PERL_USE_DEVEL
    PERL_USE_SAFE_PUTENV
    USE_64_BIT_ALL
    USE_64_BIT_INT
    USE_LARGE_FILES
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_PERLIO
    USE_PERL_ATOF
  Built under linux
  Compiled at Aug 20 2024 15:21:53
  %ENV:
    PERLBREW_HOME="/home/nathan/.perlbrew"
    PERLBREW_MANPATH="/home/nathan/perl5/perlbrew/perls/perl-5.41.2/man"
    PERLBREW_PATH="/home/nathan/perl5/perlbrew/bin:/home/nathan/perl5/perlbrew/perls/perl-5.41.2/bin"
    PERLBREW_PERL="perl-5.41.2"
    PERLBREW_ROOT="/home/nathan/perl5/perlbrew"
    PERLBREW_SHELLRC_VERSION="0.98"
    PERLBREW_VERSION="0.98"
  @INC:
    /home/nathan/perl5/perlbrew/perls/perl-5.41.2/lib/site_perl/5.41.2/x86_64-linux
    /home/nathan/perl5/perlbrew/perls/perl-5.41.2/lib/site_perl/5.41.2
    /home/nathan/perl5/perlbrew/perls/perl-5.41.2/lib/5.41.2/x86_64-linux
    /home/nathan/perl5/perlbrew/perls/perl-5.41.2/lib/5.41.2
Quipyowert2 added a commit to Quipyowert2/perl-tk that referenced this issue Aug 31, 2024
If libPNG and/or JPEG libraries are not installed and Perl was compiled
with -D_FORTIFY_SOURCE, the linker will fail with a mismatched errno
error. This is caused by GCC outputting a warning when Perl/Tk's build system
picks up on the _FORTIFY_SOURCE option but not the optimization option.
The configure script checks the compiler output against the empty
string, so the warning causes it to assume there is no errno.h on the
system.

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

No branches or pull requests

1 participant