Skip to contentSkip to conversation

mm: kmemleak: Use address-of operator on section symbols

PATCH Applied Nathan Chancellor 3 participants 4 messages Feb 20, 2020 – Feb 21, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mm: kmemleak: Use address-of operator on section symbols

Clang warns:

These are not true arrays, they are linker defined symbols, which are just addresses. Using the address of operator silences the warning and does not change the resulting assembly with either clang/ld.lld or gcc/ld (tested with diff + objdump -Dr).

---

v1 -> v2: https://lore.kernel.org/lkml/[email protected]/

* No longer a series because there is no prerequisite patch.
* Use address-of operator instead of casting to unsigned long.

 mm/kmemleak.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
mm/kmemleak.c +1 -1
index aa6832432d6a..788dc5509539 100644
@@ -1952,7 +1952,7 @@ void __init kmemleak_init(void)
 	create_object((unsigned long)__bss_start, __bss_stop - __bss_start,
 		      KMEMLEAK_GREY, GFP_ATOMIC);
 	/* only register .data..ro_after_init if not within .data */
-	if (__start_ro_after_init < _sdata || __end_ro_after_init > _edata)
+	if (&__start_ro_after_init < &_sdata || &__end_ro_after_init > &_edata)
 		create_object((unsigned long)__start_ro_after_init,
 			      __end_ro_after_init - __start_ro_after_init,
 			      KMEMLEAK_GREY, GFP_ATOMIC);
Signature · 1 line
2.25.1
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 10 lines · Nathan Chancellor

Clang warns:

These are not true arrays, they are linker defined symbols, which are just addresses. Using the address of operator silences the warning and does not change the resulting assembly with either clang/ld.lld or gcc/ld (tested with diff + objdump -Dr).

maintainer
#2 lore raw
In reply to Nathan Chancellor
Quoted 6 lines · On Wed, 19 Feb 2020 22:15:51 -0700 Nathan Chancellor…

Clang warns:

These are not true arrays, they are linker defined symbols, which are just addresses. Using the address of operator silences the warning and does not change the resulting assembly with either clang/ld.lld or gcc/ld (tested with diff + objdump -Dr).

I guess you forgot to quote the clang output?

#3 lore raw
Quoted 10 lines · Andrew Morton
Quoted 6 lines · On Wed, 19 Feb 2020 22:15:51 -0700 Nathan Chancellor…

Clang warns:

These are not true arrays, they are linker defined symbols, which are just addresses. Using the address of operator silences the warning and does not change the resulting assembly with either clang/ld.lld or gcc/ld (tested with diff + objdump -Dr).

I guess you forgot to quote the clang output?

Ugh yes, sorry. I can send a v3 later or here it is if you want to stitch it in:

../mm/kmemleak.c:1955:28: warning: array comparison always evaluates to a constant [-Wtautological-compare]

        if (__start_ro_after_init < _sdata || __end_ro_after_init > _edata)
                                  ^
../mm/kmemleak.c:1955:60: warning: array comparison always evaluates to a constant [-Wtautological-compare]
        if (__start_ro_after_init < _sdata || __end_ro_after_init > _edata)
                                                                  ^

2 warnings generated.

Cheers,
Nathan