Skip to contentSkip to conversation

Fix clang build, partially

PATCH In review Darren Kenny 3 participants 6 messages Jun 14, 2022 – Jul 28, 2022

lore
Share & tools
lore
#0 lore raw

cover Fix clang build, partially

To fix the build with clang, there are 2 parts needed, the first is to get a fix back into gnulib to ensure that the regex code can build, that has been submitted upstream and can be pulled in later since there is now a preference not to have patches held in GRUB's own sources but fix upstream.

But even with that fix, GRUB won't build, and that is because Clang replaces the 'abort()' call with '__builtin_trap', but the abort call is surrounded by an EXPORT_FUNC(), which is valid for GCC.

The core of the issue is that the gensymlist script should be filtering out any call starting with '__builtin_', so this patch will add that filter.

Thanks,

Darren.

Darren Kenny (1):
gensymlist: fix clang build with exporting of __builtin_trap

 grub-core/gensymlist.sh | 1 +
 1 file changed, 1 insertion(+)
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/1 gensymlist: fix clang build with exporting of __builtin_trap

clang expands the abort function to __builtin_trap, but that cannot be exported.

The script that generates the symlist.c file should also exclude any symbols that start with __builtin_.

---
 grub-core/gensymlist.sh | 1 +
 1 file changed, 1 insertion(+)
grub-core/gensymlist.sh +1 -0
index 5074ef6aad58..a2e5b85d0a71 100644
@@ -58,6 +58,7 @@ EOF
 
 (while read LINE; do echo $LINE; done) \
   | grep -v '^#' \
+  | grep -v 'EXPORT_FUNC *(__builtin_[a-zA-Z0-9_]*)' \
   | sed -n \
         -e '/EXPORT_FUNC *([a-zA-Z0-9_]*)/{s/.*EXPORT_FUNC *(\([a-zA-Z0-9_]*\)).*/      {"\1", \1, 1},/;p;}' \
         -e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR *(\([a-zA-Z0-9_]*\)).*/      {"\1", (void *) \&\1, 0},/;p;}' \
Signature · 1 line
2.31.1
#2 lore raw

Re: [PATCH 1/1] gensymlist: fix clang build with exporting of __builtin_trap

Quoted 6 lines · Darren Kenny

clang expands the abort function to __builtin_trap, but that cannot be exported.

The script that generates the symlist.c file should also exclude any symbols that start with __builtin_.

This patch will break many platforms including PPC which rely on functions like __builtin_bswap*

Quoted 26 lines
---
 grub-core/gensymlist.sh | 1 +
 1 file changed, 1 insertion(+)
grub-core/gensymlist.sh +1 -1
index 5074ef6aad58..a2e5b85d0a71 100644
@@ -58,6 +58,7 @@ EOF
 
 (while read LINE; do echo $LINE; done) \
   | grep -v '^#' \
+  | grep -v 'EXPORT_FUNC *(__builtin_[a-zA-Z0-9_]*)' \
   | sed -n \
         -e '/EXPORT_FUNC *([a-zA-Z0-9_]*)/{s/.*EXPORT_FUNC *(\([a-zA-Z0-9_]*\)).*/      {"\1", \1, 1},/;p;}' \
         -e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR *(\([a-zA-Z0-9_]*\)).*/      {"\1", (void *) \&\1, 0},/;p;}' \
--

2.31.1

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Signature · 2 lines
Regards
Vladimir 'phcoder' Serbinenko
#3 lore raw

Re: [PATCH 1/1] gensymlist: fix clang build with exporting of __builtin_trap

In reply to Darren Kenny

Correct solution is to provide __builtin_trap ourselves. Likely it would be a wrapper around grub_abort

Le mar. 14 juin 2022, 15:37, Darren Kenny <[email protected]> a écrit :

Quoted 34 lines

clang expands the abort function to __builtin_trap, but that cannot be exported.

The script that generates the symlist.c file should also exclude any symbols that start with __builtin_.

---
 grub-core/gensymlist.sh | 1 +
 1 file changed, 1 insertion(+)
grub-core/gensymlist.sh +1 -0
index 5074ef6aad58..a2e5b85d0a71 100644
@@ -58,6 +58,7 @@ EOF
 
 (while read LINE; do echo $LINE; done) \
   | grep -v '^#' \
+  | grep -v 'EXPORT_FUNC *(__builtin_[a-zA-Z0-9_]*)' \
   | sed -n \
         -e '/EXPORT_FUNC *([a-zA-Z0-9_]*)/{s/.*EXPORT_FUNC
 *(\([a-zA-Z0-9_]*\)).*/      {"\1", \1, 1},/;p;}' \
         -e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR

*(\([a-zA-Z0-9_]*\)).*/ {"\1", (void *) \&\1, 0},/;p;}' \
--
2.31.1

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#4 lore raw

Re: [PATCH 1/1] gensymlist: fix clang build with exporting of __builtin_trap

Quoted 2 lines · On Tue, 14 Jun 2022 18:55:18 +0200 "Vladimir 'phcoder' Serbinenko"…

Correct solution is to provide __builtin_trap ourselves. Likely it would be a wrapper around grub_abort

This seems like tacit support for at least the direction of my patch removing the use of __builtin_trap[1] which was introduced recently in cd37d3d39 (gnulib: Drop no-abort.patch) and which uses grub_abort() instead of __builtin_trap. The only other place that could potentially use __builtin_trap is in grub-core/lib/gnulib/verify.h in the "assume" macro. However, I don't see anywhere that macro is being used. Though Daniel was wondering what was wrong with defining abort in grub-core/lib/posix_wrap/stdlib.h as had been done in db7337a3d (grub-core/lib/posix_wrap/stdlib.h (abort): Removed).

Glenn

[1] https://lists.gnu.org/archive/html/grub-devel/2022-03/msg00220.html

Quoted 38 lines

Le mar. 14 juin 2022, 15:37, Darren Kenny <[email protected]> a écrit :

Quoted 34 lines

clang expands the abort function to __builtin_trap, but that cannot be exported.

The script that generates the symlist.c file should also exclude any symbols that start with __builtin_.

---
 grub-core/gensymlist.sh | 1 +
 1 file changed, 1 insertion(+)
grub-core/gensymlist.sh +1 -0
index 5074ef6aad58..a2e5b85d0a71 100644
@@ -58,6 +58,7 @@ EOF
 
 (while read LINE; do echo $LINE; done) \
   | grep -v '^#' \
+  | grep -v 'EXPORT_FUNC *(__builtin_[a-zA-Z0-9_]*)' \
   | sed -n \
         -e '/EXPORT_FUNC *([a-zA-Z0-9_]*)/{s/.*EXPORT_FUNC
 *(\([a-zA-Z0-9_]*\)).*/      {"\1", \1, 1},/;p;}' \
         -e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR

*(\([a-zA-Z0-9_]*\)).*/ {"\1", (void *) \&\1, 0},/;p;}' \
--
2.31.1

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#5 lore raw

Re: [PATCH 1/1] gensymlist: fix clang build with exporting of __builtin_trap

Hi Glenn,

Finally managed to get a look at this again, and I agree Glenn that your patch fixes this issue too, so I withdraw my patch.

Thanks,

Darren.

Quoted 63 lines · Glenn Washburn
Quoted 2 lines · On Tue, 14 Jun 2022 18:55:18 +0200 "Vladimir 'phcoder' Serbinenko"…

Correct solution is to provide __builtin_trap ourselves. Likely it would be a wrapper around grub_abort

This seems like tacit support for at least the direction of my patch removing the use of __builtin_trap[1] which was introduced recently in cd37d3d39 (gnulib: Drop no-abort.patch) and which uses grub_abort() instead of __builtin_trap. The only other place that could potentially use __builtin_trap is in grub-core/lib/gnulib/verify.h in the "assume" macro. However, I don't see anywhere that macro is being used. Though Daniel was wondering what was wrong with defining abort in grub-core/lib/posix_wrap/stdlib.h as had been done in db7337a3d (grub-core/lib/posix_wrap/stdlib.h (abort): Removed).

Glenn

[1] https://lists.gnu.org/archive/html/grub-devel/2022-03/msg00220.html

Quoted 33 lines

Le mar. 14 juin 2022, 15:37, Darren Kenny <[email protected]> a écrit :

Quoted 29 lines

clang expands the abort function to __builtin_trap, but that cannot be exported.

The script that generates the symlist.c file should also exclude any symbols that start with __builtin_.

---
 grub-core/gensymlist.sh | 1 +
 1 file changed, 1 insertion(+)
grub-core/gensymlist.sh +1 -0
index 5074ef6aad58..a2e5b85d0a71 100644
@@ -58,6 +58,7 @@ EOF
 
 (while read LINE; do echo $LINE; done) \
   | grep -v '^#' \
+  | grep -v 'EXPORT_FUNC *(__builtin_[a-zA-Z0-9_]*)' \
   | sed -n \
         -e '/EXPORT_FUNC *([a-zA-Z0-9_]*)/{s/.*EXPORT_FUNC
 *(\([a-zA-Z0-9_]*\)).*/      {"\1", \1, 1},/;p;}' \
         -e '/EXPORT_VAR *([a-zA-Z0-9_]*)/{s/.*EXPORT_VAR

*(\([a-zA-Z0-9_]*\)).*/ {"\1", (void *) \&\1, 0},/;p;}' \
--
2.31.1

Quoted 5 lines
Quoted 5 lines

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel