aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXi Ruoyao <xry111@xry111.site>2024-01-18 16:29:43 +0800
committerXi Ruoyao <xry111@xry111.site>2024-01-18 16:46:54 +0800
commit2e88f8d572dc5ae1d50819613a45c59a1c0fc405 (patch)
treec47fb588baa54d000f78fe962d6da7a6795e083a
parent3626aa30487772be32d2b6ca591137ce88e9d616 (diff)
ncurses: Don't create library aliases in an unsafe mannerxry111/ncurses-disallow-abi-mismatch
TL;DR DO NOT REVERT THIS COMMIT BECAUSE IT MAKES A BLFS PACKAGE FTBFS! The ABI of libncurses and libncursesw (et al) are different so it's unsafe to use libncursesw as a drop-in of libncurses. If an application is built with -D_XOPEN_SOURCES={a number >= 500} or -D_XOPEN_SOURCES_EXTENDED, it should use libncursesw; otherwise it should use libncurses. Otherwise there will be an ABI mismatch and it may cause segfault etc. An exception: the terminfo (terminal capability database) support in libncursesw and libncurses are the same. Thus the distros providing both libncursesw and libncurses configure Ncurses --with-termlib so the terminfo support will be a standalone libtinfo library, instead of being duplicated in two ncurses libraries. Create a symlink so the packages only using terminfo support from ncurses can find the libncursesw library and use it. If a BLFS package using libncurses FTBFS after this change, we need to define -D_XOPEN_SOURCES=600 (as pkg-config --cflags ncursesw outputs), before hacking it to use libncursesw instead.
-rw-r--r--chapter01/changelog.xml15
-rw-r--r--chapter06/ncurses.xml24
-rw-r--r--chapter08/ncurses.xml26
3 files changed, 52 insertions, 13 deletions
diff --git a/chapter01/changelog.xml b/chapter01/changelog.xml
index 15bd9a519..a45affaf1 100644
--- a/chapter01/changelog.xml
+++ b/chapter01/changelog.xml
@@ -41,6 +41,21 @@
-->
<listitem>
+ <para>2024-01-18</para>
+ <itemizedlist>
+ <listitem>
+ <para>[xry111] - No longer create the ncurses "compatibility"
+ linker scripts which may potentially cause an ABI mismatch. Fixes
+ <ulink url="&lfs-ticket-root;5415">#5415</ulink>. Note that if
+ a package fails to build after this change, the package likely
+ had been suffering from the subtle ABI mismatch in the past. So
+ such build failures should be analyzed case by case, not papered
+ over with the "compatibility" linker scripts.</para>
+ </listitem>
+ </itemizedlist>
+ </listitem>
+
+ <listitem>
<para>2024-01-09</para>
<itemizedlist>
<listitem>
diff --git a/chapter06/ncurses.xml b/chapter06/ncurses.xml
index 8d7c8b1fe..1d4afdda8 100644
--- a/chapter06/ncurses.xml
+++ b/chapter06/ncurses.xml
@@ -156,7 +156,7 @@ popd</userinput></screen>
<para>Install the package:</para>
<screen><userinput remap="install">make DESTDIR=$LFS TIC_PATH=$(pwd)/build/progs/tic install
-echo "INPUT(-lncursesw)" > $LFS/usr/lib/libncurses.so</userinput></screen>
+ln -sv libncursesw.so $LFS/usr/lib/libtinfo.so</userinput></screen>
<!--
<para>Remove an unneeded static library not handled by
<command>configure</command>:</para>
@@ -176,12 +176,24 @@ echo "INPUT(-lncursesw)" > $LFS/usr/lib/libncurses.so</userinput></screen>
</varlistentry>
<varlistentry>
- <term><command>echo "INPUT(-lncursesw)" > $LFS/usr/lib/libncurses.so</command></term>
+ <term><command>ln -sv libncursesw.so $LFS/usr/lib/libtinfo.so</command></term>
<listitem>
- <para>The <filename>libncurses.so</filename> library is needed by
- a few packages we will build soon. We create this small linker
- script, as this is what is done in <xref
- linkend="chapter-building-system"/>.</para>
+ <para>On the distros providing both the wide-character
+ <systemitem class='library'>libncursesw</systemitem>
+ and the traditional 8-bit
+ <systemitem class='library'>libncurses</systemitem> libraries,
+ the terminal capability database (terminfo) support
+ functionalities of Ncurses are separated into a library named
+ <systemitem class='library'>libtinfo</systemitem> so they
+ are not duplicated in these two Ncurses libraries. Thus some
+ packages will refer to
+ <systemitem class='library'>libtinfo</systemitem> for the
+ terminfo support. On LFS we don't build the 8-bit
+ <systemitem class='library'>libncurses</systemitem> library,
+ so we've configured Ncurses to include the terminfo support
+ in <systemitem class='library'>libncursesw</systemitem>. Create
+ a symlink for the packages expecting the terminfo support from
+ <systemitem class='library'>libtinfo</systemitem>.</para>
</listitem>
</varlistentry>
diff --git a/chapter08/ncurses.xml b/chapter08/ncurses.xml
index b51099001..e8d286b6d 100644
--- a/chapter08/ncurses.xml
+++ b/chapter08/ncurses.xml
@@ -105,7 +105,9 @@
These wide-character libraries are usable in both multibyte and
traditional 8-bit locales, while normal libraries work properly
only in 8-bit locales. Wide-character and normal libraries are
- source-compatible, but not binary-compatible.</para>
+ source-compatible, but not binary-compatible: an application must
+ be recompiled with the proper preprocessor definitions before
+ being linked against the wide-character libraries.</para>
</listitem>
</varlistentry>
@@ -138,15 +140,25 @@ install -vm755 dest/usr/lib/libncursesw.so.&ncurses-version; /usr/lib
rm -v dest/usr/lib/libncursesw.so.&ncurses-version;
cp -av dest/* /</userinput></screen>
- <para>Many applications still expect the linker to be able to find
- non-wide-character Ncurses libraries. Trick such applications into linking with
- wide-character libraries by means of symlinks and linker scripts:</para>
+ <para>For applications looking up 8-bit Ncurses libraries via
+ <command>pkg-config</command>, create several symlinks so
+ <command>pkg-config</command> will output the information of the
+ wide-character Ncurses libraries instead. This is safe because
+ <command>pkg-config</command> also provides the <envar>CFLAGS</envar>,
+ including the preprocessor definitions needed to ensure the application
+ code compiled with the same ABI as the wide-character libraries:</para>
+
+ <!-- For apps directly using -lncurses w/o querying pkg-config, we
+ must tell them to use -D_XOPEN_SOURCE=600 and -lncursesw explicitly
+ to avoid an ABI mismatch. We shall handle them case by case. -->
<screen><userinput remap="install">for lib in ncurses form panel menu ; do
- rm -vf /usr/lib/lib${lib}.so
- echo "INPUT(-l${lib}w)" &gt; /usr/lib/lib${lib}.so
ln -sfv ${lib}w.pc /usr/lib/pkgconfig/${lib}.pc
done</userinput></screen>
+<!--
+
+ commented out because using libncursesw.so for libcurses.so is unsafe,
+ and there shouldn't be "old" apps searching for "libcursesw".
<para>Finally, make sure that old applications that look for
<filename class="libraryfile">-lcurses</filename> at build time are still
@@ -155,7 +167,7 @@ done</userinput></screen>
<screen><userinput remap="install">rm -vf /usr/lib/libcursesw.so
echo "INPUT(-lncursesw)" &gt; /usr/lib/libcursesw.so
ln -sfv libncurses.so /usr/lib/libcurses.so</userinput></screen>
-
+-->
<para>If desired, install the Ncurses documentation:</para>
<screen><userinput remap="install">cp -v -R doc -T /usr/share/doc/ncurses-&ncurses-version;</userinput></screen>