Skip to contentSkip to conversation

package/dmalloc: cleanups and ssp workaround (branch yem/dmalloc)

PATCH Superseded Yann E. MORIN 2 participants 7 messages Feb 8, 2023 – Mar 4, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover package/dmalloc: cleanups and ssp workaround (branch yem/dmalloc)

Hello All!

This short series cleans up (a bit) our dmalloc package, and disables SSP altogether to avoid build failures due to limitations in the dmalloc build system.

Regards,
Yann E. MORIN.

----------------------------------------------------------------
Yann E. MORIN (3):
package/dmalloc: convert existing patch to git format package/dmalloc: use actual patches rather than sed-ing package/dmalloc: don't use SSP

 .../dmalloc/0001-configure-fix-build-on-mips.patch | 87 ++++++++++++++++++++++
 package/dmalloc/0001-mips.patch                    | 45 -----------
 ...003-configure-allow-overriding-some-tests.patch | 80 ++++++++++++++++++++
 ...e-the-configure-detected-or-user-supplied.patch | 50 +++++++++++++
 ...onfigure-use-LD-instead-of-hard-coding-ld.patch | 67 +++++++++++++++++
 package/dmalloc/dmalloc.mk                         | 24 +++---
 6 files changed, 296 insertions(+), 57 deletions(-)
 create mode 100644 package/dmalloc/0001-configure-fix-build-on-mips.patch
 delete mode 100644 package/dmalloc/0001-mips.patch
 create mode 100644 package/dmalloc/0003-configure-allow-overriding-some-tests.patch
 create mode 100644 package/dmalloc/0004-Makefile-use-the-configure-detected-or-user-supplied.patch
 create mode 100644 package/dmalloc/0005-configure-use-LD-instead-of-hard-coding-ld.patch
Signature · 10 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 561 099 427 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

PATCH 1/3 package/dmalloc: convert existing patch to git format

We're going to add more patches, so let's cleanup our historical baggage...

Cc Fabrice Fontaine <[email protected]>
---
 .../0001-configure-fix-build-on-mips.patch    | 87 +++++++++++++++++++
 package/dmalloc/0001-mips.patch               | 45 ----------
 2 files changed, 87 insertions(+), 45 deletions(-)
 create mode 100644 package/dmalloc/0001-configure-fix-build-on-mips.patch
 delete mode 100644 package/dmalloc/0001-mips.patch
package/dmalloc/0001-configure-fix-build-on-mips.patch new file +87 -0
new file mode 100644
index 0000000000..90a6ad7f54
@@ -0,0 +1,87 @@
+From af6adb3f5f05be4faa88a5aa83296c388c8085e7 Mon Sep 17 00:00:00 2001
+From: "Yann E. MORIN" <[email protected]>
+Date: Wed, 8 Feb 2023 12:30:10 +0100
+Subject: [PATCH] configure: fix build on mips
+
+This patch is a historical baggage that Buildroot has carried for ages
+(since 2006), and the reason for it are notentirely clear.
+
+Since dmalloc is pretty tricky, and as this patch has not been
+identified as causing issues, we keep it; we just add the configure.ac
+patchlet to match the one in configure.
+
+As for the title, the original patch was named dmalloc-mips.patch, so
+presumably it fixes some mips issue; let's title the commit that way.
+
+Signed-off-by: Yann E. MORIN <[email protected]>
+---
+ configure    |  4 ++--
+ configure.ac |  2 +-
+ return.h     | 16 +++-------------
+ 3 files changed, 6 insertions(+), 16 deletions(-)
+
+diff --git a/configure b/configure
+index d52a1e8..c18dfb2 100755
+--- a/configure
++++ b/configure
+@@ -5413,8 +5413,8 @@ fi
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking return.h macros work" >&5
+ $as_echo_n "checking return.h macros work... " >&6; }
+ if test "$cross_compiling" = yes; then :
+-   $as_echo "#define RETURN_MACROS_WORK 0" >>confdefs.h
+- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
++   $as_echo "#define RETURN_MACROS_WORK 1" >>confdefs.h
++ { $as_echo "$as_me:${as_lineno-$LINENO}: result: assume yes (cross-compiling)" >&5
+ $as_echo "no" >&6; }
+ 
+ else
+diff --git a/configure.ac b/configure.ac
+index a5295f1..9740fdc 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -705,7 +705,7 @@ int main()
+ ])],
+ [ AC_DEFINE(RETURN_MACROS_WORK, 1) AC_MSG_RESULT([yes]) ],
+ [ AC_DEFINE(RETURN_MACROS_WORK, 0) AC_MSG_RESULT([no]) ],
+-[ AC_DEFINE(RETURN_MACROS_WORK, 0) AC_MSG_RESULT([no]) ]
++[ AC_DEFINE(RETURN_MACROS_WORK, 1) AC_MSG_RESULT([assume yes (cross-compiling)]) ]
+ )
+ 
+ ##############################################################################
+diff --git a/return.h b/return.h
+index 9d3f5f1..d916c7a 100644
+--- a/return.h
++++ b/return.h
+@@ -117,26 +117,16 @@
+ /*************************************/
+ 
+ /*
+- * For DEC Mips machines running Ultrix
++ * For Mips machines running Linux
+  */
+ #if __mips
+ 
+-/*
+- * I have no idea how to get inline assembly with the default cc.
+- * Anyone know how?
+- */
+-
+-#if 0
+-
+ /*
+  * NOTE: we assume here that file is global.
+  *
+- * $31 is the frame pointer.  $2 looks to be the return address but maybe
+- * not consistently.
++ * $31 is the return address.
+  */
+-#define GET_RET_ADDR(file)	asm("sw $2, file")
+-
+-#endif
++#define GET_RET_ADDR(file)	asm("sw $31, %0" : "=m" (file))
+ 
+ #endif /* __mips */
+ 
+-- 
+2.25.1
+
package/dmalloc/0001-mips.patch deleted +0 -45

45 lines not on this page · raw message

Signature · 6 lines
2.25.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw

Re: [Buildroot] [PATCH 1/3] package/dmalloc: convert existing patch to git format

Quoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Yann" == Yann E MORIN <[email protected]> writes:

We're going to add more patches, so let's cleanup our historical baggage...

Cc Fabrice Fontaine <[email protected]>

Committed to 2022.11.x and 2022.02.x, thanks.

Signature · 5 lines
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#3 lore raw

PATCH 2/3 package/dmalloc: use actual patches rather than sed-ing

In reply to Yann E. MORIN

Our dmalloc packaging is very old and carries historical baggage and idiosyncracies that we have long stopped doing in the rest ofthe code base.

Drop our post-patch hooks that seds the configure and Makefile.in files, and add patches (that could be upstreamed one day).

We provide the results in the environment, like would be done with actual autoconf cache variables (ac_cv_*).

Note: those are the result of cleaning up for further patches that did not manifest because it was too complex to add proper SSP support to dmalloc (instead, we're going to forcibly disable it in the following commit).

Note-2: those patches have not been submitted upstream, as it's mostly
dead: even though there's een some commit activities recently-ish, there has been no review or comments or the many PR pending for many years now.

Cc Fabrice Fontaine <[email protected]>
---
 ...onfigure-allow-overriding-some-tests.patch | 80 +++++++++++++++++++
 ...-configure-detected-or-user-supplied.patch | 50 ++++++++++++
 ...ure-use-LD-instead-of-hard-coding-ld.patch | 67 ++++++++++++++++
 package/dmalloc/dmalloc.mk                    | 17 ++--
 4 files changed, 202 insertions(+), 12 deletions(-)
 create mode 100644 package/dmalloc/0003-configure-allow-overriding-some-tests.patch
 create mode 100644 package/dmalloc/0004-Makefile-use-the-configure-detected-or-user-supplied.patch
 create mode 100644 package/dmalloc/0005-configure-use-LD-instead-of-hard-coding-ld.patch
package/dmalloc/0003-configure-allow-overriding-some-tests.patch new file +80 -0
new file mode 100644
index 0000000000..3003e8cbe4
@@ -0,0 +1,80 @@
+From 9d57d4353c82110c609f36f91986277343d4ee45 Mon Sep 17 00:00:00 2001
+From: "Yann E. MORIN" <[email protected]>
+Date: Wed, 8 Feb 2023 13:26:56 +0100
+Subject: [PATCH] configure: allow overriding some tests
+
+Some tests use AC_RUN_IFELSE, so they do not work for cross-compilation.
+
+Allow the user to provide these results from the environment.
+
+Signed-off-by: Yann E. MORIN <[email protected]>
+---
+ configure    | 6 +++---
+ configure.ac | 6 +++---
+ 2 files changed, 6 insertions(+), 6 deletions(-)
+
+diff --git a/configure b/configure
+index c18dfb2..d165962 100755
+--- a/configure
++++ b/configure
+@@ -4540,7 +4540,7 @@ fi
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking strdup macro" >&5
+ $as_echo_n "checking strdup macro... " >&6; }
+ if test "$cross_compiling" = yes; then :
+-  ac_cv_strdup_macro=no
++  ac_cv_strdup_macro="${ac_cv_strdup_macro-no}"
+ 
+ else
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+@@ -4578,7 +4578,7 @@ $as_echo "$ac_cv_strdup_macro" >&6; }
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking strndup macro" >&5
+ $as_echo_n "checking strndup macro... " >&6; }
+ if test "$cross_compiling" = yes; then :
+-  ac_cv_strndup_macro=no
++  ac_cv_strndup_macro="${ac_cv_strndup_macro-no}"
+ 
+ else
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+@@ -4753,7 +4753,7 @@ done
+ 
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking basic-block size" >&5
+ $as_echo_n "checking basic-block size... " >&6; }
+-ac_cv_page_size=0
++ac_cv_page_size="${ac_cv_page_size-0}"
+ if test $ac_cv_page_size = 0; then
+    if test "$cross_compiling" = yes; then :
+    ac_cv_page_size=0
+diff --git a/configure.ac b/configure.ac
+index 9740fdc..51bdf4d 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -292,7 +292,7 @@ int main() { return 1; }
+ ]])],
+ [ac_cv_strdup_macro=yes],
+ [ac_cv_strdup_macro=no],
+-[ac_cv_strdup_macro=no]
++[ac_cv_strdup_macro="${ac_cv_strdup_macro-no}"]
+ )
+ AC_MSG_RESULT([$ac_cv_strdup_macro])
+ 
+@@ -316,7 +316,7 @@ int main() { return 1; }
+ ]])],
+ [ac_cv_strndup_macro=yes],
+ [ac_cv_strndup_macro=no],
+-[ac_cv_strndup_macro=no]
++[ac_cv_strndup_macro="${ac_cv_strndup_macro-no}"]
+ )
+ AC_MSG_RESULT([$ac_cv_strndup_macro])
+ 
+@@ -390,7 +390,7 @@ AC_MSG_RESULT([$ac_cv_use_mmap])
+ #
+ AC_CHECK_FUNCS(getpagesize)
+ AC_MSG_CHECKING([basic-block size])
+-ac_cv_page_size=0
++ac_cv_page_size="${ac_cv_page_size-0}"
+ if test $ac_cv_page_size = 0; then
+    AC_RUN_IFELSE([AC_LANG_SOURCE([
+ #if HAVE_UNISTD_H
+-- 
+2.25.1
+
package/dmalloc/0004-Makefile-use-the-configure-detected-or-user-supplied.patch new file +50 -0

50 lines not on this page · raw message

package/dmalloc/0005-configure-use-LD-instead-of-hard-coding-ld.patch new file +67 -0

67 lines not on this page · raw message

package/dmalloc/dmalloc.mk +5 -12
index 81ac467277..6b90f810b2 100644
@@ -44,18 +44,11 @@ ifeq ($(BR2_TOOLCHAIN_HAS_GCC_BUG_63261),y)
 DMALLOC_CFLAGS += -O0
 endif
 
-DMALLOC_CONF_ENV = CFLAGS="$(DMALLOC_CFLAGS)"
-
-define DMALLOC_POST_PATCH
-	$(SED) 's/^ac_cv_page_size=0$$/ac_cv_page_size=12/' $(@D)/configure
-	$(SED) 's/ac_cv_strdup_macro=no$$/ac_cv_strdup_macro=yes/' $(@D)/configure
-	$(SED) 's/ac_cv_strndup_macro=no$$/ac_cv_strndup_macro=yes/' $(@D)/configure
-	$(SED) 's/(ld -/($${LD-ld} -/' $(@D)/configure
-	$(SED) 's/'\''ld -/"$${LD-ld}"'\'' -/' $(@D)/configure
-	$(SED) 's/ar cr/$$(AR) cr/' $(@D)/Makefile.in
-endef
-
-DMALLOC_POST_PATCH_HOOKS += DMALLOC_POST_PATCH
+DMALLOC_CONF_ENV = \
+	CFLAGS="$(DMALLOC_CFLAGS)" \
+	ac_cv_page_size=12 \
+	ac_cv_strdup_macro=yes \
+	ac_cv_strndup_macro=yes
 
 # both DESTDIR and PREFIX are ignored..
 define DMALLOC_INSTALL_STAGING_CMDS
Signature · 6 lines
2.25.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#4 lore raw

Re: [Buildroot] [PATCH 2/3] package/dmalloc: use actual patches rather than sed-ing

Quoted 17 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Yann" == Yann E MORIN <[email protected]> writes:

Our dmalloc packaging is very old and carries historical baggage and idiosyncracies that we have long stopped doing in the rest ofthe code base.

Drop our post-patch hooks that seds the configure and Makefile.in files, and add patches (that could be upstreamed one day).

We provide the results in the environment, like would be done with actual autoconf cache variables (ac_cv_*).

Note: those are the result of cleaning up for further patches that did not manifest because it was too complex to add proper SSP support to dmalloc (instead, we're going to forcibly disable it in the following commit).

Quoted 7 lines

Note-2: those patches have not been submitted upstream, as it's mostly
dead: even though there's een some commit activities recently-ish, there has been no review or comments or the many PR pending for many years now.

Cc Fabrice Fontaine <[email protected]>

Committed to 2022.11.x and 2022.02.x, thanks.

Signature · 5 lines
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#5 lore raw

PATCH 3/3 package/dmalloc: don't use SSP

In reply to Yann E. MORIN

dmalloc directly calls into $(LD) to generate a shared library our of the static one.

To detet what command it should run, ./configure tries various incantations of ld with various command line options until one does not fail. One of those is (basically):

    $(LD) --whole-archive -o contest.o.t contest.a

This makes ./configure conclude what the command to link a shared library in the Makefile should be, and thus stores that in a variable:

    shlinkargs='$(LD) --whole-archive -o $@'

... which is then AC_SUBST()ed into Makefile.in with a rule like:

    $(SHLIB): $(LIBRARY)
        @shlinkargs@ $(LIRARY)

which once substiuted, gives:

    $(SHLIB): $(LIBRARY)
        $(LD) --whole-archive -o $@ $(LIRARY)

However, when SSP is enabled, the __stack_chk_fail_local and co symbols are provided by additional libraries or object files, and that is the responsibility of gcc to pass those when linking. But as dmalloc directly calls ld, it misses those.

Changing dmalloc to use $(CC) is not trivial, however.

First, we can't pass LD=$(TARGET_CC), otherwise the whole package explodes [0]: indeed --whole-archive is unknown to gcc, so it must be passed as -Wl,--whole archive instead. So we'd need to add a new test that uses $(CC), like so:

    $(CC) -Wl,--whole-archive -o contest.o.t contest.a

However, in that case, gcc does pass additional libs/objs (like, for eample, the SSP ones) to the linker. But then those are also inc;luded in the whole-archive section. This causes the linker to add all the symbols form those libs/objs, even those not needed for SSP; on some archs, like PPC, that may require floating point symbols (__muldiv3 et al.) which are in another library, and thus the linked can't find them.

The proper solution wouild be to add -Wl,--no-whole-archive, but that would have to be added _after_ the library we want to link, i.e.e we should be able to evntually run:

    $(CC) -Wl,--whole-archive -o $@ $(LIRARY) -Wl,--no-whole-archive

That would require that we introduce a new variable that is added _afgter_ the $(LIBRARY), e.g. @shlinkargs_post@ or so...

This is a bigger endeavour than we want to pursue...

Since dmalloc is a debugging utility, it is not supposed to go into production builds, and during debugging, it would not be surprising that it needs to poke around arrays to debug them.

So, we go the easier route: disable SSP altogether.

[0] with lots of nce colors, but that's not the point, is it?

Cc Fabrice Fontaine <[email protected]>
---
 package/dmalloc/dmalloc.mk | 7 +++++++
 1 file changed, 7 insertions(+)
package/dmalloc/dmalloc.mk +7 -0
index 6b90f810b2..5bd6691725 100644
@@ -14,6 +14,13 @@ DMALLOC_LICENSE_FILES = LICENSE.txt
 DMALLOC_INSTALL_STAGING = YES
 DMALLOC_CFLAGS = $(TARGET_CFLAGS)
 
+# dmalloc uses $(LD) to link, and thus misses the object files or libs that
+# are needed to provide the __stack_chk_fail_local and co. symbols. Changing
+# to use $(CC) is really more complex that we'd like. Since dmalloc is
+# involved in debugging memory allocation, it is not expected to be a
+# production library, so we do not care that much that it has SSP.
+DMALLOC_CFLAGS += -fno-stack-protector
+
 ifeq ($(BR2_STATIC_LIBS),y)
 DMALLOC_CONF_OPTS += --disable-shlib
 else
Signature · 6 lines
2.25.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#6 lore raw

Re: [Buildroot] [PATCH 3/3] package/dmalloc: don't use SSP

Quoted 59 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Yann" == Yann E MORIN <[email protected]> writes:

dmalloc directly calls into $(LD) to generate a shared library our of the static one.

To detet what command it should run, ./configure tries various incantations of ld with various command line options until one does not fail. One of those is (basically):

    $(LD) --whole-archive -o contest.o.t contest.a

This makes ./configure conclude what the command to link a shared library in the Makefile should be, and thus stores that in a variable:

    shlinkargs='$(LD) --whole-archive -o $@'

... which is then AC_SUBST()ed into Makefile.in with a rule like:

    $(SHLIB): $(LIBRARY)
        @shlinkargs@ $(LIRARY)

which once substiuted, gives:

    $(SHLIB): $(LIBRARY)
        $(LD) --whole-archive -o $@ $(LIRARY)

However, when SSP is enabled, the __stack_chk_fail_local and co symbols are provided by additional libraries or object files, and that is the responsibility of gcc to pass those when linking. But as dmalloc directly calls ld, it misses those.

Changing dmalloc to use $(CC) is not trivial, however.

First, we can't pass LD=$(TARGET_CC), otherwise the whole package explodes [0]: indeed --whole-archive is unknown to gcc, so it must be passed as -Wl,--whole archive instead. So we'd need to add a new test that uses $(CC), like so:

    $(CC) -Wl,--whole-archive -o contest.o.t contest.a

However, in that case, gcc does pass additional libs/objs (like, for eample, the SSP ones) to the linker. But then those are also inc;luded in the whole-archive section. This causes the linker to add all the symbols form those libs/objs, even those not needed for SSP; on some archs, like PPC, that may require floating point symbols (__muldiv3 et al.) which are in another library, and thus the linked can't find them.

The proper solution wouild be to add -Wl,--no-whole-archive, but that would have to be added _after_ the library we want to link, i.e.e we should be able to evntually run:

    $(CC) -Wl,--whole-archive -o $@ $(LIRARY) -Wl,--no-whole-archive

That would require that we introduce a new variable that is added _afgter_ the $(LIBRARY), e.g. @shlinkargs_post@ or so...

This is a bigger endeavour than we want to pursue...

Since dmalloc is a debugging utility, it is not supposed to go into production builds, and during debugging, it would not be surprising that it needs to poke around arrays to debug them.

Quoted 6 lines

So, we go the easier route: disable SSP altogether.

[0] with lots of nce colors, but that's not the point, is it?

Cc Fabrice Fontaine <[email protected]>

Committed to 2022.11.x and 2022.02.x, thanks.

Signature · 5 lines
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot