From 175c3f1d2da74072ef134037d394e63c9da4b014 Mon Sep 17 00:00:00 2001 From: green Date: Mon, 6 Aug 2001 14:21:57 +0000 Subject: Previously, the ELF linker would always just store the pointer to a filename passed in via the module loader functions in the GDB "sharedlibrary" support structures. This isn't good, since the pointer would become stale in almost every case (not the pre-loaded case, of course). Change this to malloc()ed copy of the string and finally fix the reason that gdb -k's "sharedlibrary" command stopped working. Obtained from: LOMAC/FreeBSD (cf. NAI Labs) --- sys/kern/link_elf.c | 6 +++++- sys/kern/link_elf_obj.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'sys') diff --git a/sys/kern/link_elf.c b/sys/kern/link_elf.c index faaf160..785d23a 100644 --- a/sys/kern/link_elf.c +++ b/sys/kern/link_elf.c @@ -530,6 +530,7 @@ link_elf_load_file(linker_class_t cls, const char* filename, linker_file_t* resu int symstrindex; int symcnt; int strcnt; + char *newfilename; GIANT_REQUIRED; @@ -788,7 +789,9 @@ link_elf_load_file(linker_class_t cls, const char* filename, linker_file_t* resu #ifdef DDB GDB_STATE(RT_ADD); ef->gdb.l_addr = lf->address; - ef->gdb.l_name = filename; + newfilename = malloc(strlen(filename) + 1, M_LINKER, M_WAITOK); + strcpy(newfilename, filename); + ef->gdb.l_name = (const char *)newfilename; ef->gdb.l_ld = ef->dynamic; link_elf_add_gdb(&ef->gdb); GDB_STATE(RT_CONSISTENT); @@ -819,6 +822,7 @@ link_elf_unload_file(linker_file_t file) #ifdef DDB if (ef->gdb.l_ld) { GDB_STATE(RT_DELETE); + free((void *)ef->gdb.l_name, M_LINKER); link_elf_delete_gdb(&ef->gdb); GDB_STATE(RT_CONSISTENT); } diff --git a/sys/kern/link_elf_obj.c b/sys/kern/link_elf_obj.c index faaf160..785d23a 100644 --- a/sys/kern/link_elf_obj.c +++ b/sys/kern/link_elf_obj.c @@ -530,6 +530,7 @@ link_elf_load_file(linker_class_t cls, const char* filename, linker_file_t* resu int symstrindex; int symcnt; int strcnt; + char *newfilename; GIANT_REQUIRED; @@ -788,7 +789,9 @@ link_elf_load_file(linker_class_t cls, const char* filename, linker_file_t* resu #ifdef DDB GDB_STATE(RT_ADD); ef->gdb.l_addr = lf->address; - ef->gdb.l_name = filename; + newfilename = malloc(strlen(filename) + 1, M_LINKER, M_WAITOK); + strcpy(newfilename, filename); + ef->gdb.l_name = (const char *)newfilename; ef->gdb.l_ld = ef->dynamic; link_elf_add_gdb(&ef->gdb); GDB_STATE(RT_CONSISTENT); @@ -819,6 +822,7 @@ link_elf_unload_file(linker_file_t file) #ifdef DDB if (ef->gdb.l_ld) { GDB_STATE(RT_DELETE); + free((void *)ef->gdb.l_name, M_LINKER); link_elf_delete_gdb(&ef->gdb); GDB_STATE(RT_CONSISTENT); } -- cgit v1.1