[PATCH] Fix compilation error due to new glibc implemented the strlcpy function
by Lianbo Jiang
Crash-utility implemented its own strlcpy(), but for now the latest
glibc has added the strlcpy function to POSIX version(which is derived
from OpenBSD). Eventually this caused the follow compilation error:
# make -j8 lzo
...
gcc -c -g -DX86_64 -DLZO -DGDB_10_2 -g -O2 kernel.c -I./gdb-10.2/bfd -I./gdb-10.2/include
In file included from global_data.c:18:
defs.h:5556:8: error: conflicting types for ‘strlcpy’; have ‘size_t(char *, char *, size_t)’ {aka ‘long unsigned int(char *, char *, long unsigned int)’}
5556 | size_t strlcpy(char *, char *, size_t);
| ^~~~~~~
In file included from memory.c:19:
defs.h:5556:8: error: conflicting types for ‘strlcpy’; have ‘size_t(char *, char *, size_t)’ {aka ‘long unsigned int(char *, char *, long unsigned int)’}
5556 | size_t strlcpy(char *, char *, size_t);
| ^~~~~~~
...
Related glibc commits:
[1] 454a20c8756c ("Implement strlcpy and strlcat [BZ #178]")
[2] d2fda60e7c40 ("manual: Manual update for strlcat, strlcpy, wcslcat, wclscpy")
[3] 388ae538ddcb ("hurd: Add strlcpy, strlcat, wcslcpy, wcslcat to libc.abilist")
To fix the current issues, let's declare the strlcpy() as a weak
function, and keep the same parameter types with the latest glibc
function.
Signed-off-by: Lianbo Jiang <lijiang(a)redhat.com>
---
defs.h | 2 +-
tools.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/defs.h b/defs.h
index 8f7d1fa0aba6..26afe232cc3e 100644
--- a/defs.h
+++ b/defs.h
@@ -5553,7 +5553,7 @@ uint32_t swap32(uint32_t, int);
uint64_t swap64(uint64_t, int);
ulong *get_cpumask_buf(void);
int make_cpumask(char *, ulong *, int, int *);
-size_t strlcpy(char *, char *, size_t);
+size_t strlcpy(char *, const char *, size_t) __attribute__ ((__weak__));
struct rb_node *rb_first(struct rb_root *);
struct rb_node *rb_parent(struct rb_node *, struct rb_node *);
struct rb_node *rb_right(struct rb_node *, struct rb_node *);
diff --git a/tools.c b/tools.c
index 392a79707e61..0f2db108838a 100644
--- a/tools.c
+++ b/tools.c
@@ -6795,7 +6795,7 @@ make_cpumask_error:
* always be NULL-terminated.
*/
size_t
-strlcpy(char *dest, char *src, size_t size)
+strlcpy(char *dest, const char *src, size_t size)
{
size_t ret = strlen(src);
--
2.37.1
1 year, 4 months
[PATCH] Fix failure of gathering task table on linux-next (Linux 6.5 and later?)
by HAGIO KAZUHITO(萩尾 一仁)
From: Kazuhito Hagio <k-hagio-ab(a)nec.com>
(The following commit is now in linux-next.)
Kernel commit 757777eef55b ("pid: Replace struct pid 1-element array
with flex-array") changed pid.numbers[1] to pid.numbers[]. With this,
the size of struct pid does not contain the size of struct upid:
(gdb) ptype /o struct pid
/* offset | size */ type = struct pid {
/* 0 | 4 */ refcount_t count;
...
/* 96 | 0 */ struct upid numbers[];
^^^^ ^^^
/* total size (bytes): 96 */
} ^^^^
As a result, in refresh_xarray_task_table(), crash does not read the
data of pid.numbers[0].ns and cannot gather the task table correctly.
$ crash vmlinux vmcore
...
WARNING: active task ffff936992ad0000 on cpu 1 not found in PID hash
...
crash> ps -S
RU: 9
crash>
Increase the size of reading struct pid by SIZE(upid) in this case.
Signed-off-by: Kazuhito Hagio <k-hagio-ab(a)nec.com>
---
defs.h | 1 +
symbols.c | 3 +++
task.c | 10 ++++++++--
3 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/defs.h b/defs.h
index 3e7d6cfbc6a8..dc7c822055f0 100644
--- a/defs.h
+++ b/defs.h
@@ -2424,6 +2424,7 @@ struct array_table {
int task_struct_rlim;
int signal_struct_rlim;
int vm_numa_stat;
+ int pid_numbers;
};
/*
diff --git a/symbols.c b/symbols.c
index 7b1d59203b90..ec2878bf41d6 100644
--- a/symbols.c
+++ b/symbols.c
@@ -8741,6 +8741,8 @@ builtin_array_length(char *s, int len, int *two_dim)
lenptr = &array_table.signal_struct_rlim;
else if (STREQ(s, "vm_numa_stat"))
lenptr = &array_table.vm_numa_stat;
+ else if (STREQ(s, "pid.numbers"))
+ lenptr = &array_table.pid_numbers;
if (!lenptr) /* not stored */
return(len);
@@ -11139,6 +11141,7 @@ dump_offset_table(char *spec, ulong makestruct)
ARRAY_LENGTH(signal_struct_rlim));
fprintf(fp, " vm_numa_stat: %d\n",
ARRAY_LENGTH(vm_numa_stat));
+ fprintf(fp, " pid_numbers: %d\n", ARRAY_LENGTH(pid_numbers));
if (spec) {
int in_size_table, in_array_table, arrays, offsets, sizes;
diff --git a/task.c b/task.c
index 2b7467b4193d..d1af4df025b9 100644
--- a/task.c
+++ b/task.c
@@ -352,6 +352,7 @@ task_init(void)
MEMBER_OFFSET_INIT(upid_ns, "upid", "ns");
MEMBER_OFFSET_INIT(upid_pid_chain, "upid", "pid_chain");
MEMBER_OFFSET_INIT(pid_numbers, "pid", "numbers");
+ ARRAY_LENGTH_INIT(len, pid_numbers, "pid.numbers", NULL, 0);
MEMBER_OFFSET_INIT(pid_tasks, "pid", "tasks");
tt->init_pid_ns = symbol_value("init_pid_ns");
}
@@ -2574,6 +2575,7 @@ refresh_xarray_task_table(void)
char *tp;
struct list_pair xp;
char *pidbuf;
+ long pid_size = SIZE(pid);
if (DUMPFILE() && (tt->flags & TASK_INIT_DONE)) /* impossible */
return;
@@ -2603,8 +2605,12 @@ refresh_xarray_task_table(void)
if (CRASHDEBUG(1))
console("xarray: count: %ld\n", count);
+ /* 6.5: 757777eef55b changed pid.numbers[1] to numbers[] */
+ if (ARRAY_LENGTH(pid_numbers) == 0)
+ pid_size += SIZE(upid);
+
retries = 0;
- pidbuf = GETBUF(SIZE(pid));
+ pidbuf = GETBUF(pid_size);
retry_xarray:
if (retries && DUMPFILE())
@@ -2672,7 +2678,7 @@ retry_xarray:
* - get task from address of task->pids[0]
*/
if (!readmem(next, KVADDR, pidbuf,
- SIZE(pid), "pid", RETURN_ON_ERROR|QUIET)) {
+ pid_size, "pid", RETURN_ON_ERROR|QUIET)) {
error(INFO, "\ncannot read pid struct from xarray\n");
if (DUMPFILE())
continue;
--
2.31.1
1 year, 4 months