* [PATCH 0/2] s390: Fix memory leaks in assembler and linker
@ 2025-01-22 13:39 Jens Remus
2025-01-22 13:39 ` [PATCH 1/2] s390: s390_machinemode leak Jens Remus
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Jens Remus @ 2025-01-22 13:39 UTC (permalink / raw)
To: binutils, Andreas Krebbel; +Cc: Jens Remus
Motivated by Alan's recent work I ran the assembler and linker test
suites on s390x with ASAN enabled as follows and fixed the reported
memory leaks in s390-specific code.
$ ../configure --disable-gdb --disable-gdbserver --disable-gold \
--disable-sim --disable-readline --disable-nls --disable-werror \
CFLAGS="-g -O2 -fsanitize=address,undefined" \
CXXFLAGS="-g -O2 -fsanitize=address,undefined"
$ make -j $(nproc)
$ ASAN_OPTIONS=fast_unwind_on_malloc=false make check-gas
$ ASAN_OPTIONS=fast_unwind_on_malloc=false make check-ld
Regards,
Jens
Jens Remus (2):
s390: s390_machinemode leak
s390: s390_machine leak
gas/config/tc-s390.c | 39 +++++++++-------------
gas/testsuite/gas/s390/machine-parsing-1.l | 3 +-
gas/testsuite/gas/s390/machine-parsing-1.s | 3 ++
3 files changed, 20 insertions(+), 25 deletions(-)
--
2.45.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] s390: s390_machinemode leak
2025-01-22 13:39 [PATCH 0/2] s390: Fix memory leaks in assembler and linker Jens Remus
@ 2025-01-22 13:39 ` Jens Remus
2025-01-22 13:39 ` [PATCH 2/2] s390: s390_machine leak Jens Remus
2025-01-27 7:38 ` [PATCH 0/2] s390: Fix memory leaks in assembler and linker Andreas Krebbel
2 siblings, 0 replies; 5+ messages in thread
From: Jens Remus @ 2025-01-22 13:39 UTC (permalink / raw)
To: binutils, Andreas Krebbel; +Cc: Jens Remus
This resolves the following memory leak reported by ASAN:
Direct leak of 17 byte(s) in 1 object(s) allocated from:
#0 0x3ffb32fbb1d in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
#1 0x2aa149861cf in xmalloc ../../libiberty/xmalloc.c:149
#2 0x2aa149868ff in xstrdup ../../libiberty/xstrdup.c:34
#3 0x2aa1312391f in s390_machinemode ../../gas/config/tc-s390.c:2241
#4 0x2aa130ddc7b in read_a_source_file ../../gas/read.c:1293
#5 0x2aa1304f7bf in perform_an_assembly_pass ../../gas/as.c:1223
#6 0x2aa1304f7bf in main ../../gas/as.c:1436
#7 0x3ffb282be35 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
#8 0x3ffb282bf33 in __libc_start_main_impl ../csu/libc-start.c:360
#9 0x2aa1305758f (/home/jremus/git/binutils/build-asan/gas/as-new+0x2d5758f) (BuildId: ...)
gas/
* config/tc-s390.c (s390_machinemode): Free mode_string before
returning.
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
---
gas/config/tc-s390.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/gas/config/tc-s390.c b/gas/config/tc-s390.c
index e7a7e7e04f1f..113b9f41a1ec 100644
--- a/gas/config/tc-s390.c
+++ b/gas/config/tc-s390.c
@@ -2287,6 +2287,7 @@ s390_machinemode (int ignore ATTRIBUTE_UNUSED)
s390_setup_opcodes ();
}
+ xfree (mode_string);
demand_empty_rest_of_line ();
}
--
2.45.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] s390: s390_machine leak
2025-01-22 13:39 [PATCH 0/2] s390: Fix memory leaks in assembler and linker Jens Remus
2025-01-22 13:39 ` [PATCH 1/2] s390: s390_machinemode leak Jens Remus
@ 2025-01-22 13:39 ` Jens Remus
2025-01-27 7:38 ` [PATCH 0/2] s390: Fix memory leaks in assembler and linker Andreas Krebbel
2 siblings, 0 replies; 5+ messages in thread
From: Jens Remus @ 2025-01-22 13:39 UTC (permalink / raw)
To: binutils, Andreas Krebbel; +Cc: Jens Remus
Simplify the .machine directive parsing logic, so that cpu_string is
always xstrdup'd and can therefore always be xfree'd before returning
to the caller.
This resolves the following memory leak reported by ASAN:
Direct leak of 13 byte(s) in 3 object(s) allocated from:
#0 0x3ff8aafbb1d in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
#1 0x2aa338861cf in xmalloc ../../libiberty/xmalloc.c:149
#2 0x2aa338868ff in xstrdup ../../libiberty/xstrdup.c:34
#3 0x2aa320253cb in s390_machine ../../gas/config/tc-s390.c:2172
#4 0x2aa31fddc7b in read_a_source_file ../../gas/read.c:1293
#5 0x2aa31f4f7bf in perform_an_assembly_pass ../../gas/as.c:1223
#6 0x2aa31f4f7bf in main ../../gas/as.c:1436
#7 0x3ff8a02be35 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
#8 0x3ff8a02bf33 in __libc_start_main_impl ../csu/libc-start.c:360
#9 0x2aa31f5758f (/home/jremus/git/binutils/build-asan/gas/as-new+0x2d5758f) (BuildId: ...)
While at it add tests with double quoted .machine
"<cpu>[+<extension>...]" values.
gas/
* config/tc-s390.c (s390_machine): Simplify parsing and free
cpu_string before returning.
gas/testsuite/
* gas/s390/machine-parsing-1.l: Add tests with double quoted
values.
* gas/s390/machine-parsing-1.s: Likewise.
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
---
gas/config/tc-s390.c | 38 ++++++++--------------
gas/testsuite/gas/s390/machine-parsing-1.l | 3 +-
gas/testsuite/gas/s390/machine-parsing-1.s | 3 ++
3 files changed, 19 insertions(+), 25 deletions(-)
diff --git a/gas/config/tc-s390.c b/gas/config/tc-s390.c
index 113b9f41a1ec..b651acc3cf90 100644
--- a/gas/config/tc-s390.c
+++ b/gas/config/tc-s390.c
@@ -2146,32 +2146,21 @@ s390_machine (int ignore ATTRIBUTE_UNUSED)
SKIP_WHITESPACE ();
- if (*input_line_pointer == '"')
- {
- int len;
- cpu_string = demand_copy_C_string (&len);
- }
- else
- {
- char c;
-
- cpu_string = input_line_pointer;
- do
- {
- char * str;
+ {
+ char c;
- c = get_symbol_name (&str);
- c = restore_line_pointer (c);
- if (c == '+')
- ++ input_line_pointer;
- }
- while (c == '+');
+ c = get_symbol_name (&cpu_string);
+ while (c == '+')
+ {
+ char *str;
- c = *input_line_pointer;
- *input_line_pointer = 0;
- cpu_string = xstrdup (cpu_string);
- (void) restore_line_pointer (c);
- }
+ c = restore_line_pointer (c);
+ input_line_pointer++;
+ c = get_symbol_name (&str);
+ }
+ cpu_string = xstrdup (cpu_string);
+ (void) restore_line_pointer (c);
+ }
if (cpu_string != NULL)
{
@@ -2217,6 +2206,7 @@ s390_machine (int ignore ATTRIBUTE_UNUSED)
}
}
+ xfree (cpu_string);
demand_empty_rest_of_line ();
}
diff --git a/gas/testsuite/gas/s390/machine-parsing-1.l b/gas/testsuite/gas/s390/machine-parsing-1.l
index 1a83ec81897d..8850eff54320 100644
--- a/gas/testsuite/gas/s390/machine-parsing-1.l
+++ b/gas/testsuite/gas/s390/machine-parsing-1.l
@@ -1,2 +1,3 @@
.*: Assembler messages:
-.*:5: Error: invalid machine .foo.*
+.*:7: Error: invalid machine .foo.*
+.*:8: Error: invalid machine .foo.*
diff --git a/gas/testsuite/gas/s390/machine-parsing-1.s b/gas/testsuite/gas/s390/machine-parsing-1.s
index ea402bca793f..aa2a206a5fc1 100644
--- a/gas/testsuite/gas/s390/machine-parsing-1.s
+++ b/gas/testsuite/gas/s390/machine-parsing-1.s
@@ -1,5 +1,8 @@
.text
foo:
.machine z13
+ .machine "z13"
.machine z13+vx+novx+htm+nohtm+vx+novx+htm+nohtm
+ .machine "z13+vx+novx+htm+nohtm+vx+novx+htm+nohtm"
.machine foo
+ .machine "foo"
--
2.45.2
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] s390: Fix memory leaks in assembler and linker
2025-01-22 13:39 [PATCH 0/2] s390: Fix memory leaks in assembler and linker Jens Remus
2025-01-22 13:39 ` [PATCH 1/2] s390: s390_machinemode leak Jens Remus
2025-01-22 13:39 ` [PATCH 2/2] s390: s390_machine leak Jens Remus
@ 2025-01-27 7:38 ` Andreas Krebbel
2025-01-27 15:46 ` Jens Remus
2 siblings, 1 reply; 5+ messages in thread
From: Andreas Krebbel @ 2025-01-27 7:38 UTC (permalink / raw)
To: Jens Remus, binutils
Hi Jens,
ok to apply. Thanks for fixing this!
Andreas
On 1/22/25 2:39 PM, Jens Remus wrote:
> Motivated by Alan's recent work I ran the assembler and linker test
> suites on s390x with ASAN enabled as follows and fixed the reported
> memory leaks in s390-specific code.
>
> $ ../configure --disable-gdb --disable-gdbserver --disable-gold \
> --disable-sim --disable-readline --disable-nls --disable-werror \
> CFLAGS="-g -O2 -fsanitize=address,undefined" \
> CXXFLAGS="-g -O2 -fsanitize=address,undefined"
> $ make -j $(nproc)
> $ ASAN_OPTIONS=fast_unwind_on_malloc=false make check-gas
> $ ASAN_OPTIONS=fast_unwind_on_malloc=false make check-ld
>
> Regards,
> Jens
>
> Jens Remus (2):
> s390: s390_machinemode leak
> s390: s390_machine leak
>
> gas/config/tc-s390.c | 39 +++++++++-------------
> gas/testsuite/gas/s390/machine-parsing-1.l | 3 +-
> gas/testsuite/gas/s390/machine-parsing-1.s | 3 ++
> 3 files changed, 20 insertions(+), 25 deletions(-)
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/2] s390: Fix memory leaks in assembler and linker
2025-01-27 7:38 ` [PATCH 0/2] s390: Fix memory leaks in assembler and linker Andreas Krebbel
@ 2025-01-27 15:46 ` Jens Remus
0 siblings, 0 replies; 5+ messages in thread
From: Jens Remus @ 2025-01-27 15:46 UTC (permalink / raw)
To: Andreas Krebbel, binutils
Thanks! Committed to mainline.
Regards,
Jens
On 27.01.2025 08:38, Andreas Krebbel wrote:
> Hi Jens,
>
> ok to apply. Thanks for fixing this!
>
> Andreas
>
> On 1/22/25 2:39 PM, Jens Remus wrote:
>> Motivated by Alan's recent work I ran the assembler and linker test
>> suites on s390x with ASAN enabled as follows and fixed the reported
>> memory leaks in s390-specific code.
>>
>> $ ../configure --disable-gdb --disable-gdbserver --disable-gold \
>> --disable-sim --disable-readline --disable-nls --disable-werror \
>> CFLAGS="-g -O2 -fsanitize=address,undefined" \
>> CXXFLAGS="-g -O2 -fsanitize=address,undefined"
>> $ make -j $(nproc)
>> $ ASAN_OPTIONS=fast_unwind_on_malloc=false make check-gas
>> $ ASAN_OPTIONS=fast_unwind_on_malloc=false make check-ld
>>
>> Regards,
>> Jens
>>
>> Jens Remus (2):
>> s390: s390_machinemode leak
>> s390: s390_machine leak
>>
>> gas/config/tc-s390.c | 39 +++++++++-------------
>> gas/testsuite/gas/s390/machine-parsing-1.l | 3 +-
>> gas/testsuite/gas/s390/machine-parsing-1.s | 3 ++
>> 3 files changed, 20 insertions(+), 25 deletions(-)
>>
--
Jens Remus
Linux on Z Development (D3303)
+49-7031-16-1128 Office
jremus@de.ibm.com
IBM
IBM Deutschland Research & Development GmbH; Vorsitzender des Aufsichtsrats: Wolfgang Wendt; Geschäftsführung: David Faller; Sitz der Gesellschaft: Böblingen; Registergericht: Amtsgericht Stuttgart, HRB 243294
IBM Data Privacy Statement: https://www.ibm.com/privacy/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-01-27 15:46 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-22 13:39 [PATCH 0/2] s390: Fix memory leaks in assembler and linker Jens Remus
2025-01-22 13:39 ` [PATCH 1/2] s390: s390_machinemode leak Jens Remus
2025-01-22 13:39 ` [PATCH 2/2] s390: s390_machine leak Jens Remus
2025-01-27 7:38 ` [PATCH 0/2] s390: Fix memory leaks in assembler and linker Andreas Krebbel
2025-01-27 15:46 ` Jens Remus
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).