diff mbox series

btrfs: avoid linker error in btrfs_find_create_tree_block()

Message ID 20250306105900.1961011-1-maharmstone@fb.com (mailing list archive)
State New
Headers show
Series btrfs: avoid linker error in btrfs_find_create_tree_block() | expand

Commit Message

Mark Harmstone March 6, 2025, 10:58 a.m. UTC
The inline function btrfs_is_testing() is hardcoded to return 0 if
CONFIG_BTRFS_FS_RUN_SANITY_TESTS is not set. Currently we're relying on
the compiler optimizing out the call to alloc_test_extent_buffer() in
btrfs_find_create_tree_block(), as it's not been defined (it's behind an
 #ifdef).

Add a stub version of alloc_test_extent_buffer() to avoid linker errors
on non-standard optimization levels. This problem was seen on GCC 14
with -O0.

Signed-off-by: Mark Harmstone <maharmstone@fb.com>
---
 fs/btrfs/extent_io.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

Comments

Mark Harmstone March 6, 2025, 11:03 a.m. UTC | #1
The context to this is that I'm fed up of seeing "<optimized out>" in 
GDB, and am trying to get the kernel to compile with -O0 for development 
purposes.

There's still a couple of issues elsewhere for this to be possible, but 
this was one of the problems I ran into.

Mark

On 6/3/25 10:58, Mark Harmstone wrote:
> The inline function btrfs_is_testing() is hardcoded to return 0 if
> CONFIG_BTRFS_FS_RUN_SANITY_TESTS is not set. Currently we're relying on
> the compiler optimizing out the call to alloc_test_extent_buffer() in
> btrfs_find_create_tree_block(), as it's not been defined (it's behind an
>   #ifdef).
> 
> Add a stub version of alloc_test_extent_buffer() to avoid linker errors
> on non-standard optimization levels. This problem was seen on GCC 14
> with -O0.
> 
> Signed-off-by: Mark Harmstone <maharmstone@fb.com>
> ---
>   fs/btrfs/extent_io.c | 10 ++++++++--
>   1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index fad42da1a6ba..03320f953817 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -2984,10 +2984,10 @@ struct extent_buffer *find_extent_buffer(struct btrfs_fs_info *fs_info,
>   	return eb;
>   }
>   
> -#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
>   struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info,
>   					u64 start)
>   {
> +#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
>   	struct extent_buffer *eb, *exists = NULL;
>   	int ret;
>   
> @@ -3023,8 +3023,14 @@ struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info,
>   free_eb:
>   	btrfs_release_extent_buffer(eb);
>   	return exists;
> -}
> +#else
> +	/*
> +	 * stub to avoid linker error when compiled with optimizations
> +	 * turned off
> +	 */
> +	return NULL;
>   #endif
> +}
>   
>   static struct extent_buffer *grab_extent_buffer(struct btrfs_fs_info *fs_info,
>   						struct folio *folio)
diff mbox series

Patch

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index fad42da1a6ba..03320f953817 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -2984,10 +2984,10 @@  struct extent_buffer *find_extent_buffer(struct btrfs_fs_info *fs_info,
 	return eb;
 }
 
-#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
 struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info,
 					u64 start)
 {
+#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
 	struct extent_buffer *eb, *exists = NULL;
 	int ret;
 
@@ -3023,8 +3023,14 @@  struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info,
 free_eb:
 	btrfs_release_extent_buffer(eb);
 	return exists;
-}
+#else
+	/*
+	 * stub to avoid linker error when compiled with optimizations
+	 * turned off
+	 */
+	return NULL;
 #endif
+}
 
 static struct extent_buffer *grab_extent_buffer(struct btrfs_fs_info *fs_info,
 						struct folio *folio)