Skip to contentSkip to conversation

meson: Use -fno-sanitize=function when available

PATCH Superseded Akihiko Odaki 3 participants 13 messages Aug 16, 2024 Arm/Amlogic Meson SoC support

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 meson: Use -fno-sanitize=function when available

Commit 23ef50ae2d0c (".gitlab-ci.d/buildtest.yml: Use -fno-sanitize=function in the clang-system job") adds -fno-sanitize=function for the CI but doesn't add the flag in the other context. Add it to meson.build for such. It is not removed from .gitlab-ci.d/buildtest.yml because -fno-sanitize=function in meson.build does not affect --extra-cflags due to argument ordering.

---
Changes in v3:
- I was not properly dropping the change of .gitlab-ci.d/buildtest.yml but only updated the message. v3 fixes this. (Thomas Huth)
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Dropped the change of: .gitlab-ci.d/buildtest.yml
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 meson.build | 1 +
 1 file changed, 1 insertion(+)
meson.build +1 -0
index 5613b62a4f42..a4169c572ba9 100644
@@ -609,6 +609,7 @@ if host_os != 'openbsd' and \
 endif
 
 qemu_common_flags += cc.get_supported_arguments(hardening_flags)
+qemu_common_flags += cc.get_supported_arguments('-fno-sanitize=function')
 
 add_global_arguments(qemu_common_flags, native: false, language: all_languages)
 add_global_link_arguments(qemu_ldflags, native: false, language: all_languages)

---
base-commit: 93b799fafd9170da3a79a533ea6f73a18de82e22
change-id: 20240714-function-7d32c723abbc

Best regards,

Signature · 1 line
Akihiko Odaki <[email protected]>
#1 lore raw
Quoted 26 lines · Akihiko Odaki

Commit 23ef50ae2d0c (".gitlab-ci.d/buildtest.yml: Use

(quoted diff) +0 -2
-fno-sanitize=function in the clang-system job") adds
-fno-sanitize=function for the CI but doesn't add the flag in the

other context. Add it to meson.build for such. It is not removed from .gitlab-ci.d/buildtest.yml because -fno-sanitize=function in meson.build does not affect --extra-cflags due to argument ordering.

---
Changes in v3:
- I was not properly dropping the change of .gitlab-ci.d/buildtest.yml but only updated the message. v3 fixes this. (Thomas Huth)
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Dropped the change of: .gitlab-ci.d/buildtest.yml
- Link to v1: https://lore.kernel.org/r/[email protected]

---
  meson.build | 1 +
  1 file changed, 1 insertion(+)
meson.build +0 -0
index 5613b62a4f42..a4169c572ba9 100644

meson.build if host_os != 'openbsd' and \ · line 612

Quoted 4 lines
meson.build +1 -0
@@ -609,6 +609,7 @@ if host_os != 'openbsd' and \
  endif
 
  qemu_common_flags += cc.get_supported_arguments(hardening_flags)
+qemu_common_flags += cc.get_supported_arguments('-fno-sanitize=function')

As I mentioned in my last mail: I think it would make sense to move this at the end of the "if get_option('tsan')" block in meson.build, since this apparently only fixes the use of "--enable-sanitizers", and cannot fix the "--extra-cflags" that a user might have specified?

Thomas

#2 lore raw
Quoted 24 lines · Thomas Huth
Quoted 23 lines · Akihiko Odaki

Commit 23ef50ae2d0c (".gitlab-ci.d/buildtest.yml: Use

(quoted diff) +0 -2
-fno-sanitize=function in the clang-system job") adds
-fno-sanitize=function for the CI but doesn't add the flag in the

other context. Add it to meson.build for such. It is not removed from .gitlab-ci.d/buildtest.yml because -fno-sanitize=function in meson.build does not affect --extra-cflags due to argument ordering.

---
Changes in v3:
- I was not properly dropping the change of .gitlab-ci.d/buildtest.yml but only updated the message. v3 fixes this. (Thomas Huth)
- Link to v2:
https://lore.kernel.org/r/[email protected]

Changes in v2:
- Dropped the change of: .gitlab-ci.d/buildtest.yml
- Link to v1:
https://lore.kernel.org/r/[email protected]
---
  meson.build | 1 +

  1 file changed, 1 insertion(+)
Quoted 11 lines
Quoted 9 lines
meson.build +0 -0
index 5613b62a4f42..a4169c572ba9 100644
@@ -609,6 +609,7 @@ if host_os != 'openbsd' and \

  endif
  qemu_common_flags += cc.get_supported_arguments(hardening_flags) +qemu_common_flags += cc.get_supported_arguments('-fno-sanitize=function')

As I mentioned in my last mail: I think it would make sense to move this at the end of the "if get_option('tsan')" block in meson.build, since this apparently only fixes the use of "--enable-sanitizers", and cannot fix the "--extra-cflags" that a user might have specified?

Sorry, I missed it. It cannot fix --extra-cflags, but it should be able to fix compiler flags specified by compiler distributor.

Regards,
Akihiko Odaki

#3 lore raw
Quoted 36 lines · Akihiko Odaki
Quoted 24 lines · Thomas Huth
Quoted 23 lines · Akihiko Odaki

Commit 23ef50ae2d0c (".gitlab-ci.d/buildtest.yml: Use

(quoted diff) +0 -2
-fno-sanitize=function in the clang-system job") adds
-fno-sanitize=function for the CI but doesn't add the flag in the

other context. Add it to meson.build for such. It is not removed from .gitlab-ci.d/buildtest.yml because -fno-sanitize=function in meson.build does not affect --extra-cflags due to argument ordering.

---
Changes in v3:
- I was not properly dropping the change of .gitlab-ci.d/buildtest.yml but only updated the message. v3 fixes this. (Thomas Huth)
- Link to v2:
https://lore.kernel.org/r/[email protected]

Changes in v2:
- Dropped the change of: .gitlab-ci.d/buildtest.yml
- Link to v1:
https://lore.kernel.org/r/[email protected]
---
  meson.build | 1 +

  1 file changed, 1 insertion(+)
Quoted 10 lines
Quoted 8 lines
meson.build +0 -0
index 5613b62a4f42..a4169c572ba9 100644
@@ -609,6 +609,7 @@ if host_os != 'openbsd' and \

  endif
  qemu_common_flags += cc.get_supported_arguments(hardening_flags) +qemu_common_flags += cc.get_supported_arguments('-fno-sanitize=function')

As I mentioned in my last mail: I think it would make sense to move this at the end of the "if get_option('tsan')" block in meson.build, since this apparently only fixes the use of "--enable-sanitizers", and cannot fix the "--extra-cflags" that a user might have specified?

Quoted 1 line

Sorry, I missed it. It cannot fix --extra-cflags, but it should be able to fix compiler flags specified by compiler distributor.

Oh, you mean that there are distros that enable -fsanitize=function by default? Can you name one? If so, I think that information should go into the patch description...?

Thomas

#4 lore raw
Quoted 38 lines · Thomas Huth
Quoted 37 lines · Akihiko Odaki
Quoted 35 lines · Thomas Huth
Quoted 28 lines · Akihiko Odaki

Commit 23ef50ae2d0c (".gitlab-ci.d/buildtest.yml: Use

(quoted diff) +0 -2
-fno-sanitize=function in the clang-system job") adds
-fno-sanitize=function for the CI but doesn't add the flag in the

other context. Add it to meson.build for such. It is not removed from .gitlab-ci.d/buildtest.yml because -fno-sanitize=function in meson.build does not affect --extra-cflags due to argument ordering.

---
Changes in v3:
- I was not properly dropping the change of .gitlab-ci.d/buildtest.yml but only updated the message. v3 fixes this. (Thomas Huth)
- Link to v2:
https://lore.kernel.org/r/[email protected]

Changes in v2:
- Dropped the change of: .gitlab-ci.d/buildtest.yml
- Link to v1:
https://lore.kernel.org/r/[email protected]
---
  meson.build | 1 +

  1 file changed, 1 insertion(+)
meson.build +0 -0
index 5613b62a4f42..a4169c572ba9 100644
@@ -609,6 +609,7 @@ if host_os != 'openbsd' and \
Quoted 4 lines

  endif
  qemu_common_flags += cc.get_supported_arguments(hardening_flags) +qemu_common_flags += cc.get_supported_arguments('-fno-sanitize=function')

As I mentioned in my last mail: I think it would make sense to move this at the end of the "if get_option('tsan')" block in meson.build, since this apparently only fixes the use of "--enable-sanitizers", and cannot fix the "--extra-cflags" that a user might have specified?

Quoted 3 lines
Quoted 1 line

Sorry, I missed it. It cannot fix --extra-cflags, but it should be able to fix compiler flags specified by compiler distributor.

Oh, you mean that there are distros that enable -fsanitize=function by default? Can you name one? If so, I think that information should go into the patch description...?

No, it is just a precaution.

Regards,
Akihiko Odaki

#5 lore raw
Quoted 38 lines · Akihiko Odaki
Quoted 37 lines · Thomas Huth
Quoted 36 lines · Akihiko Odaki
Quoted 34 lines · Thomas Huth
Quoted 28 lines · Akihiko Odaki

Commit 23ef50ae2d0c (".gitlab-ci.d/buildtest.yml: Use

(quoted diff) +0 -2
-fno-sanitize=function in the clang-system job") adds
-fno-sanitize=function for the CI but doesn't add the flag in the

other context. Add it to meson.build for such. It is not removed from .gitlab-ci.d/buildtest.yml because -fno-sanitize=function in meson.build does not affect --extra-cflags due to argument ordering.

---
Changes in v3:
- I was not properly dropping the change of .gitlab-ci.d/buildtest.yml but only updated the message. v3 fixes this. (Thomas Huth)
- Link to v2:
https://lore.kernel.org/r/[email protected]

Changes in v2:
- Dropped the change of: .gitlab-ci.d/buildtest.yml
- Link to v1:
https://lore.kernel.org/r/[email protected]
---
  meson.build | 1 +

  1 file changed, 1 insertion(+)
meson.build +0 -0
index 5613b62a4f42..a4169c572ba9 100644
@@ -609,6 +609,7 @@ if host_os != 'openbsd' and \
Quoted 3 lines

  endif
  qemu_common_flags += cc.get_supported_arguments(hardening_flags) +qemu_common_flags += cc.get_supported_arguments('-fno-sanitize=function')

As I mentioned in my last mail: I think it would make sense to move this at the end of the "if get_option('tsan')" block in meson.build, since this apparently only fixes the use of "--enable-sanitizers", and cannot fix the "--extra-cflags" that a user might have specified?

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Sorry, I missed it. It cannot fix --extra-cflags, but it should be able to fix compiler flags specified by compiler distributor.

Oh, you mean that there are distros that enable -fsanitize=function by default? Can you name one? If so, I think that information should go into the patch description...?

No, it is just a precaution.

Ok. I don't think any normal distro will enable this by default since this impacts performance of the programs, so it's either the user specifying --enable-sanitizers or the user specifying --extra-cflags="-fsanitize=...". In the latter case, your patch does not help. In the former case, I think this setting should go into the same code block as where we set -fsanitize=undefined in our meson.build file, so that it is clear where it belongs to.

Thomas

#12 lore raw
In reply to Thomas Huth
Quoted 35 lines · Thomas Huth
Quoted 34 lines · Akihiko Odaki
Quoted 32 lines · Thomas Huth
Quoted 26 lines · Akihiko Odaki

Commit 23ef50ae2d0c (".gitlab-ci.d/buildtest.yml: Use

(quoted diff) +0 -2
-fno-sanitize=function in the clang-system job") adds
-fno-sanitize=function for the CI but doesn't add the flag in the

other context. Add it to meson.build for such. It is not removed from .gitlab-ci.d/buildtest.yml because -fno-sanitize=function in meson.build does not affect --extra-cflags due to argument ordering.

---
Changes in v3:
- I was not properly dropping the change of .gitlab-ci.d/buildtest.yml but only updated the message. v3 fixes this. (Thomas Huth)
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Dropped the change of: .gitlab-ci.d/buildtest.yml
- Link to v1: https://lore.kernel.org/r/[email protected]
---
  meson.build | 1 +

  1 file changed, 1 insertion(+)
meson.build +0 -0
index 5613b62a4f42..a4169c572ba9 100644
@@ -609,6 +609,7 @@ if host_os != 'openbsd' and \
Quoted 3 lines

  endif
  qemu_common_flags += cc.get_supported_arguments(hardening_flags) +qemu_common_flags += cc.get_supported_arguments('-fno-sanitize=function')

As I mentioned in my last mail: I think it would make sense to move this at the end of the "if get_option('tsan')" block in meson.build, since this apparently only fixes the use of "--enable-sanitizers", and cannot fix the "--extra-cflags" that a user might have specified?

Quoted 3 lines
Quoted 1 line

Sorry, I missed it. It cannot fix --extra-cflags, but it should be able to fix compiler flags specified by compiler distributor.

Oh, you mean that there are distros that enable -fsanitize=function by default? Can you name one? If so, I think that information should go into the patch description...?

AFAICS, -fsanitize=function is enabled by -fsanitize=undefined.

Anyway, see also

https://lore.kernel.org/qemu-devel/[email protected]/

r~

#6 lore raw
In reply to Thomas Huth
Quoted 43 lines · Thomas Huth
Quoted 42 lines · Akihiko Odaki
Quoted 41 lines · Thomas Huth
Quoted 39 lines · Akihiko Odaki
Quoted 25 lines · Thomas Huth
Quoted 24 lines · Akihiko Odaki

Commit 23ef50ae2d0c (".gitlab-ci.d/buildtest.yml: Use

(quoted diff) +0 -2
-fno-sanitize=function in the clang-system job") adds
-fno-sanitize=function for the CI but doesn't add the flag in the

other context. Add it to meson.build for such. It is not removed from .gitlab-ci.d/buildtest.yml because -fno-sanitize=function in meson.build does not affect --extra-cflags due to argument ordering.

---
Changes in v3:
- I was not properly dropping the change of .gitlab-ci.d/buildtest.yml
   but only updated the message. v3 fixes this. (Thomas Huth)
- Link to v2:
https://lore.kernel.org/r/[email protected]

Changes in v2:
- Dropped the change of: .gitlab-ci.d/buildtest.yml
- Link to v1:
https://lore.kernel.org/r/[email protected]
---
  meson.build | 1 +

  1 file changed, 1 insertion(+)
Quoted 11 lines
Quoted 9 lines
meson.build +0 -0
index 5613b62a4f42..a4169c572ba9 100644
@@ -609,6 +609,7 @@ if host_os != 'openbsd' and \

  endif
  qemu_common_flags += cc.get_supported_arguments(hardening_flags) +qemu_common_flags += cc.get_supported_arguments('-fno-sanitize=function')

As I mentioned in my last mail: I think it would make sense to move this at the end of the "if get_option('tsan')" block in meson.build, since this apparently only fixes the use of "--enable-sanitizers", and cannot fix the "--extra-cflags" that a user might have specified?

Sorry, I missed it. It cannot fix --extra-cflags, but it should be able to fix compiler flags specified by compiler distributor.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Oh, you mean that there are distros that enable -fsanitize=function by default? Can you name one? If so, I think that information should go into the patch description...?

No, it is just a precaution.

Ok. I don't think any normal distro will enable this by default since this impacts performance of the programs, so it's either the user specifying --enable-sanitizers or the user specifying --extra-cflags="-fsanitize=...". In the latter case, your patch does not
help. In the former case, I think this setting should go into the same code block as where we set -fsanitize=undefined in our meson.build file, so that it is clear where it belongs to.

It does not look like -fno-sanitize=function belongs to the code block to me. Putting -fno-sanitize=function in the code block will make it seem to say that we should disable function sanitizer because the user requests to enable sanitizers, which makes little sense.

#7 lore raw
Quoted 45 lines · Akihiko Odaki
Quoted 44 lines · Thomas Huth
Quoted 43 lines · Akihiko Odaki
Quoted 41 lines · Thomas Huth
Quoted 37 lines · Akihiko Odaki
Quoted 24 lines · Thomas Huth
Quoted 23 lines · Akihiko Odaki

Commit 23ef50ae2d0c (".gitlab-ci.d/buildtest.yml: Use

(quoted diff) +0 -2
-fno-sanitize=function in the clang-system job") adds
-fno-sanitize=function for the CI but doesn't add the flag in the

other context. Add it to meson.build for such. It is not removed from .gitlab-ci.d/buildtest.yml because -fno-sanitize=function in meson.build does not affect --extra-cflags due to argument ordering.

---
Changes in v3:
- I was not properly dropping the change of .gitlab-ci.d/buildtest.yml but only updated the message. v3 fixes this. (Thomas Huth)
- Link to v2:
https://lore.kernel.org/r/[email protected]

Changes in v2:
- Dropped the change of: .gitlab-ci.d/buildtest.yml
- Link to v1:
https://lore.kernel.org/r/[email protected]
---
  meson.build | 1 +

  1 file changed, 1 insertion(+)
Quoted 11 lines
Quoted 9 lines
meson.build +0 -0
index 5613b62a4f42..a4169c572ba9 100644
@@ -609,6 +609,7 @@ if host_os != 'openbsd' and \

  endif
  qemu_common_flags += cc.get_supported_arguments(hardening_flags) +qemu_common_flags += cc.get_supported_arguments('-fno-sanitize=function')

As I mentioned in my last mail: I think it would make sense to move this at the end of the "if get_option('tsan')" block in meson.build, since this apparently only fixes the use of "--enable-sanitizers", and cannot fix the "--extra-cflags" that a user might have specified?

Quoted 1 line

Sorry, I missed it. It cannot fix --extra-cflags, but it should be able to fix compiler flags specified by compiler distributor.

Oh, you mean that there are distros that enable -fsanitize=function by default? Can you name one? If so, I think that information should go into the patch description...?

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

No, it is just a precaution.

Ok. I don't think any normal distro will enable this by default since this impacts performance of the programs, so it's either the user specifying --enable-sanitizers or the user specifying
--extra-cflags="-fsanitize=...". In the latter case, your patch does not
help. In the former case, I think this setting should go into the same code block as where we set -fsanitize=undefined in our meson.build file, so that it is clear where it belongs to.

It does not look like -fno-sanitize=function belongs to the code block to me. Putting -fno-sanitize=function in the code block will make it seem to say that we should disable function sanitizer because the user requests to enable sanitizers, which makes little sense.

As far as I understood, -fsanitize=undefine turns on -fsanitize=function, too, or did I get that wrong? If not, how did you run into this problem? How did you enable the function sanitizer if not using --enable-sanitizers ?

Thomas

#8 lore raw
Quoted 53 lines · Thomas Huth
Quoted 52 lines · Akihiko Odaki
Quoted 50 lines · Thomas Huth
Quoted 40 lines · Akihiko Odaki
Quoted 39 lines · Thomas Huth
Quoted 38 lines · Akihiko Odaki
Quoted 36 lines · Thomas Huth
Quoted 29 lines · Akihiko Odaki

Commit 23ef50ae2d0c (".gitlab-ci.d/buildtest.yml: Use

(quoted diff) +0 -2
-fno-sanitize=function in the clang-system job") adds
-fno-sanitize=function for the CI but doesn't add the flag in the

other context. Add it to meson.build for such. It is not removed from .gitlab-ci.d/buildtest.yml because -fno-sanitize=function in meson.build does not affect --extra-cflags due to argument ordering.

---
Changes in v3:
- I was not properly dropping the change of .gitlab-ci.d/buildtest.yml
   but only updated the message. v3 fixes this. (Thomas Huth)
- Link to v2:
https://lore.kernel.org/r/[email protected]

Changes in v2:
- Dropped the change of: .gitlab-ci.d/buildtest.yml
- Link to v1:
https://lore.kernel.org/r/[email protected]
---
  meson.build | 1 +

  1 file changed, 1 insertion(+)
meson.build +0 -0
index 5613b62a4f42..a4169c572ba9 100644
@@ -609,6 +609,7 @@ if host_os != 'openbsd' and \
Quoted 4 lines

  endif
  qemu_common_flags += cc.get_supported_arguments(hardening_flags) +qemu_common_flags += cc.get_supported_arguments('-fno-sanitize=function')

As I mentioned in my last mail: I think it would make sense to move this at the end of the "if get_option('tsan')" block in meson.build, since this apparently only fixes the use of "--enable-sanitizers", and cannot fix the "--extra-cflags" that a user might have specified?

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Sorry, I missed it. It cannot fix --extra-cflags, but it should be able to fix compiler flags specified by compiler distributor.

Oh, you mean that there are distros that enable -fsanitize=function by default? Can you name one? If so, I think that information should go into the patch description...?

No, it is just a precaution.

Ok. I don't think any normal distro will enable this by default since this impacts performance of the programs, so it's either the user specifying --enable-sanitizers or the user specifying --extra-cflags="-fsanitize=...". In the latter case, your patch does
not help. In the former case, I think this setting should go into the same code block as where we set -fsanitize=undefined in our meson.build file, so that it is clear where it belongs to.

Quoted 5 lines
Quoted 1 line

It does not look like -fno-sanitize=function belongs to the code block to me. Putting -fno-sanitize=function in the code block will make it seem to say that we should disable function sanitizer because the user requests to enable sanitizers, which makes little sense.

As far as I understood, -fsanitize=undefine turns on
-fsanitize=function, too, or did I get that wrong?
If not, how did you run into this problem? How did you enable the function sanitizer if not using --enable-sanitizers ?

The point is we don't care who enables sanitizers, and unconditonally setting -fno-sanitize=function will clarify that.

#9 lore raw
Quoted 48 lines · Akihiko Odaki
Quoted 47 lines · Thomas Huth
Quoted 46 lines · Akihiko Odaki
Quoted 45 lines · Thomas Huth
Quoted 43 lines · Akihiko Odaki
Quoted 37 lines · Thomas Huth
Quoted 36 lines · Akihiko Odaki
Quoted 34 lines · Thomas Huth
Quoted 28 lines · Akihiko Odaki

Commit 23ef50ae2d0c (".gitlab-ci.d/buildtest.yml: Use

(quoted diff) +0 -2
-fno-sanitize=function in the clang-system job") adds
-fno-sanitize=function for the CI but doesn't add the flag in the

other context. Add it to meson.build for such. It is not removed from .gitlab-ci.d/buildtest.yml because -fno-sanitize=function in meson.build does not affect --extra-cflags due to argument ordering.

---
Changes in v3:
- I was not properly dropping the change of .gitlab-ci.d/buildtest.yml but only updated the message. v3 fixes this. (Thomas Huth)
- Link to v2: https://lore.kernel.org/r/20240729-function-
[email protected]

Changes in v2:
- Dropped the change of: .gitlab-ci.d/buildtest.yml
- Link to v1: https://lore.kernel.org/r/20240714-function-v1-1-
[email protected]
---
  meson.build | 1 +

  1 file changed, 1 insertion(+)
meson.build +0 -0
index 5613b62a4f42..a4169c572ba9 100644
@@ -609,6 +609,7 @@ if host_os != 'openbsd' and \
Quoted 3 lines

  endif
  qemu_common_flags += cc.get_supported_arguments(hardening_flags) +qemu_common_flags += cc.get_supported_arguments('-fno-sanitize=function')

As I mentioned in my last mail: I think it would make sense to move this at the end of the "if get_option('tsan')" block in meson.build, since this apparently only fixes the use of "--enable-sanitizers", and cannot fix the "--extra-cflags" that a user might have specified?

Quoted 3 lines
Quoted 1 line

Sorry, I missed it. It cannot fix --extra-cflags, but it should be able to fix compiler flags specified by compiler distributor.

Oh, you mean that there are distros that enable -fsanitize=function by default? Can you name one? If so, I think that information should go into the patch description...?

No, it is just a precaution.

Quoted 9 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Ok. I don't think any normal distro will enable this by default since this impacts performance of the programs, so it's either the user specifying --enable-sanitizers or the user specifying --extra-cflags="-fsanitize=...". In the latter case, your patch does not help. In the former case, I think this setting should go into the same code block as where we set -fsanitize=undefined in our meson.build file, so that it is clear where it belongs to.

It does not look like -fno-sanitize=function belongs to the code block to me. Putting - fno-sanitize=function in the code block will make it seem to say that we should disable function sanitizer because the user requests to enable sanitizers, which makes little sense.

As far as I understood, -fsanitize=undefine turns on -fsanitize=function, too, or did I get that wrong? If not, how did you run into this problem? How did you enable the function sanitizer if not using --enable-sanitizers ?

The point is we don't care who enables sanitizers, and unconditonally setting -fno- sanitize=function will clarify that.

Argument ordering is important. You cannot just drop this in the middle of meson.build and expect anything reasonable to happen.

r~

#11 lore raw
In reply to Akihiko Odaki
Quoted 53 lines · Akihiko Odaki
Quoted 52 lines · Thomas Huth
Quoted 51 lines · Akihiko Odaki
Quoted 49 lines · Thomas Huth
Quoted 39 lines · Akihiko Odaki
Quoted 38 lines · Thomas Huth
Quoted 37 lines · Akihiko Odaki
Quoted 35 lines · Thomas Huth
Quoted 28 lines · Akihiko Odaki

Commit 23ef50ae2d0c (".gitlab-ci.d/buildtest.yml: Use

(quoted diff) +0 -2
-fno-sanitize=function in the clang-system job") adds
-fno-sanitize=function for the CI but doesn't add the flag in the

other context. Add it to meson.build for such. It is not removed from .gitlab-ci.d/buildtest.yml because -fno-sanitize=function in meson.build does not affect --extra-cflags due to argument ordering.

---
Changes in v3:
- I was not properly dropping the change of .gitlab-ci.d/buildtest.yml but only updated the message. v3 fixes this. (Thomas Huth)
- Link to v2:
https://lore.kernel.org/r/[email protected]

Changes in v2:
- Dropped the change of: .gitlab-ci.d/buildtest.yml
- Link to v1:
https://lore.kernel.org/r/[email protected]
---
  meson.build | 1 +

  1 file changed, 1 insertion(+)
meson.build +0 -0
index 5613b62a4f42..a4169c572ba9 100644
@@ -609,6 +609,7 @@ if host_os != 'openbsd' and \
Quoted 4 lines

  endif
  qemu_common_flags += cc.get_supported_arguments(hardening_flags) +qemu_common_flags += cc.get_supported_arguments('-fno-sanitize=function')

As I mentioned in my last mail: I think it would make sense to move this at the end of the "if get_option('tsan')" block in meson.build, since this apparently only fixes the use of "--enable-sanitizers", and cannot fix the "--extra-cflags" that a user might have specified?

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Sorry, I missed it. It cannot fix --extra-cflags, but it should be able to fix compiler flags specified by compiler distributor.

Oh, you mean that there are distros that enable -fsanitize=function by default? Can you name one? If so, I think that information should go into the patch description...?

No, it is just a precaution.

Ok. I don't think any normal distro will enable this by default since this impacts performance of the programs, so it's either the user specifying --enable-sanitizers or the user specifying --extra-cflags="-fsanitize=...". In the latter case, your patch does not
help. In the former case, I think this setting should go into the same code block as where we set -fsanitize=undefined in our meson.build file, so that it is clear where it belongs to.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

It does not look like -fno-sanitize=function belongs to the code block to me. Putting -fno-sanitize=function in the code block will make it seem to say that we should disable function sanitizer because the user requests to enable sanitizers, which makes little sense.

As far as I understood, -fsanitize=undefine turns on -fsanitize=function, too, or did I get that wrong? If not, how did you run into this problem? How did you enable the function sanitizer if not using --enable-sanitizers ?

The point is we don't care who enables sanitizers, and unconditonally setting -fno-sanitize=function will clarify that.

I think I tend to disagree here. If users enabled saitize=undefined it with --extra-cflags, they also have to disable sanitize=function with --extra-cflags, so listing this unconditionally in our meson.build is a red herring when people are looking at the file.

Thomas

#10 lore raw
In reply to Richard Henderson
Quoted 59 lines · Richard Henderson
Quoted 58 lines · Akihiko Odaki
Quoted 57 lines · Thomas Huth
Quoted 55 lines · Akihiko Odaki
Quoted 47 lines · Thomas Huth
Quoted 46 lines · Akihiko Odaki
Quoted 44 lines · Thomas Huth
Quoted 38 lines · Akihiko Odaki
Quoted 25 lines · Thomas Huth
Quoted 24 lines · Akihiko Odaki

Commit 23ef50ae2d0c (".gitlab-ci.d/buildtest.yml: Use

(quoted diff) +0 -2
-fno-sanitize=function in the clang-system job") adds
-fno-sanitize=function for the CI but doesn't add the flag in the

other context. Add it to meson.build for such. It is not removed from .gitlab-ci.d/buildtest.yml because -fno-sanitize=function in meson.build does not affect --extra-cflags due to argument ordering.

---
Changes in v3:
- I was not properly dropping the change of .gitlab-ci.d/buildtest.yml
   but only updated the message. v3 fixes this. (Thomas Huth)
- Link to v2: https://lore.kernel.org/r/20240729-function-
[email protected]

Changes in v2:
- Dropped the change of: .gitlab-ci.d/buildtest.yml
- Link to v1:
https://lore.kernel.org/r/20240714-function-v1-1- [email protected]
---
  meson.build | 1 +

  1 file changed, 1 insertion(+)
Quoted 11 lines
Quoted 9 lines
meson.build +0 -0
index 5613b62a4f42..a4169c572ba9 100644
@@ -609,6 +609,7 @@ if host_os != 'openbsd' and \

  endif
  qemu_common_flags += cc.get_supported_arguments(hardening_flags) +qemu_common_flags += cc.get_supported_arguments('-fno-sanitize=function')

As I mentioned in my last mail: I think it would make sense to move this at the end of the "if get_option('tsan')" block in meson.build, since this apparently only fixes the use of "--enable-sanitizers", and cannot fix the "--extra-cflags" that a user might have specified?

Quoted 1 line

Sorry, I missed it. It cannot fix --extra-cflags, but it should be able to fix compiler flags specified by compiler distributor.

Oh, you mean that there are distros that enable -fsanitize=function by default? Can you name one? If so, I think that information should go into the patch description...?

Quoted 5 lines
Quoted 1 line

No, it is just a precaution.

Ok. I don't think any normal distro will enable this by default since this impacts performance of the programs, so it's either the user specifying --enable-sanitizers or the user specifying --extra-cflags="-fsanitize=...". In the latter case, your patch
does not help. In the former case, I think this setting should go into the same code block as where we set -fsanitize=undefined in our meson.build file, so that it is clear where it belongs to.

It does not look like -fno-sanitize=function belongs to the code block to me. Putting - fno-sanitize=function in the code block will make it seem to say that we should disable function sanitizer because the user requests to enable sanitizers, which makes little sense.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

As far as I understood, -fsanitize=undefine turns on
-fsanitize=function, too, or did I get that wrong?
If not, how did you run into this problem? How did you enable the function sanitizer if not using --enable-sanitizers ?

The point is we don't care who enables sanitizers, and unconditonally setting -fno- sanitize=function will clarify that.

Argument ordering is important.  You cannot just drop this in the middle of meson.build and expect anything reasonable to happen.

That is a good point. We should add -fno-sanitize=function immediately after -fsanitize=undefined; I will submit v4 with that change.

Regards,
Akihiko Odaki