Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
215ed793
T
Third Party Musl
项目概览
OpenHarmony
/
Third Party Musl
9 个月 前同步成功
通知
37
Star
125
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Musl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
215ed793
编写于
1月 11, 2022
作者:
C
caifuzhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
解决关于动态库内存泄漏问题
Signed-off-by:
N
caifuzhou
<
caifuzhou@huawei.com
>
上级
da026e99
变更
10
展开全部
隐藏空白更改
内联
并排
Showing
10 changed file
with
2671 addition
and
0 deletion
+2671
-0
libc-test/src/functional/BUILD.gn
libc-test/src/functional/BUILD.gn
+3
-0
libc-test/src/functional/dlclose_reset.c
libc-test/src/functional/dlclose_reset.c
+72
-0
libc-test/src/functional/dlclose_reset_dso.c
libc-test/src/functional/dlclose_reset_dso.c
+33
-0
libc-test/src/functional/test_src_functional.gni
libc-test/src/functional/test_src_functional.gni
+1
-0
libc-test/test_template.gni
libc-test/test_template.gni
+5
-0
musl_src.gni
musl_src.gni
+3
-0
porting/linux/user/ldso/dynlink.c
porting/linux/user/ldso/dynlink.c
+2429
-0
porting/linux/user/src/internal/dynlink.h
porting/linux/user/src/internal/dynlink.h
+109
-0
porting/linux/user/src/ldso/dlclose.c
porting/linux/user/src/ldso/dlclose.c
+14
-0
scripts/runtest_Windows.bat
scripts/runtest_Windows.bat
+2
-0
未找到文件。
libc-test/src/functional/BUILD.gn
浏览文件 @
215ed793
...
...
@@ -18,6 +18,8 @@ group("functional_test") {
test_sharedlib("dlopen_dso") {
}
test_sharedlib("dlclose_reset_dso") {
}
test_sharedlib("tls_init_dso") {
}
test_sharedlib("tls_align_dso") {
...
...
@@ -28,6 +30,7 @@ group("dso_shared") {
deps = [
":dlopen_dso",
":dlclose_reset_dso",
":tls_align_dso",
":tls_init_dso",
]
...
...
libc-test/src/functional/dlclose_reset.c
0 → 100644
浏览文件 @
215ed793
#include <dlfcn.h>
#include <stdio.h>
#include "test.h"
typedef
int
(
*
TEST_S_VAR
)();
typedef
int
(
*
TEST_G_VAR
)();
typedef
int
(
*
INSP_S_VAR
)();
typedef
int
(
*
INSP_G_VAR
)();
int
main
(
int
argc
,
char
*
argv
[])
{
char
buf
[
512
];
void
*
h
=
NULL
;
void
*
g
=
NULL
;
TEST_S_VAR
test_s_var
=
NULL
;
TEST_G_VAR
test_g_var
=
NULL
;
INSP_S_VAR
insp_s_var
=
NULL
;
INSP_G_VAR
insp_g_var
=
NULL
;
int
s_var
=
0
;
int
g_var
=
0
;
if
(
!
t_pathrel
(
buf
,
sizeof
buf
,
argv
[
0
],
"libdlclose_reset_dso.so"
))
{
t_error
(
"failed to obtain relative path to libdlclose_reset_dso.so
\n
"
);
return
1
;
}
h
=
dlopen
(
buf
,
RTLD_LAZY
|
RTLD_LOCAL
);
if
(
!
h
)
t_error
(
"dlopen %s failed: %s
\n
"
,
buf
,
dlerror
());
test_s_var
=
(
TEST_S_VAR
)
dlsym
(
h
,
"test_static_var"
);
if
(
!
test_s_var
)
t_error
(
"dlsym test_static_var failed: %s
\n
"
,
dlerror
());
test_g_var
=
(
TEST_G_VAR
)
dlsym
(
h
,
"test_global_var"
);
if
(
!
test_g_var
)
t_error
(
"dlsyn test_global_var failed: %s
\n
"
,
dlerror
());
test_s_var
();
test_g_var
();
if
(
dlclose
(
h
))
t_error
(
"dlclose failed: %s
\n
"
,
dlerror
());
g
=
dlopen
(
buf
,
RTLD_LAZY
|
RTLD_LOCAL
);
if
(
!
g
)
t_error
(
"dlopen %s failed: %s
\n
"
,
buf
,
dlerror
());
insp_s_var
=
(
INSP_S_VAR
)
dlsym
(
g
,
"ret_static"
);
if
(
!
insp_s_var
)
t_error
(
"dlsym ret_static failed: %s
\n
"
,
dlerror
());
insp_g_var
=
(
INSP_G_VAR
)
dlsym
(
g
,
"ret_global"
);
if
(
!
insp_g_var
)
t_error
(
"dlsyn global_var failed: %s
\n
"
,
dlerror
());
s_var
=
insp_s_var
();
g_var
=
insp_g_var
();
if
(
s_var
!=
84
)
t_error
(
"Static variable reset failed: want s_var=84 got s_var=%d
\n
"
,
s_var
);
if
(
g_var
!=
84
)
t_error
(
"Global variable reset failed: want g_var=84 got g_var=%d
\n
"
,
g_var
);
if
(
dlclose
(
g
))
t_error
(
"dlclose failed: %s
\n
"
,
dlerror
());
}
libc-test/src/functional/dlclose_reset_dso.c
0 → 100644
浏览文件 @
215ed793
#include <stdio.h>
int
global_var
=
84
;
static
int
stat_var
=
84
;
void
test_static_var
()
{
stat_var
++
;
}
void
test_global_var
()
{
global_var
++
;
}
int
ret_static
()
{
return
stat_var
;
}
int
ret_global
()
{
return
global_var
;
}
__attribute__
((
constructor
))
void
before_main
()
{
printf
(
"before main
\n
"
);
}
__attribute__
((
destructor
))
void
after_main
()
{
printf
(
"after main
\n
"
);
}
libc-test/src/functional/test_src_functional.gni
浏览文件 @
215ed793
...
...
@@ -72,4 +72,5 @@ functional_list = [
"vfork",
"wcsstr",
"wcstol",
"dlclose_reset",
]
libc-test/test_template.gni
浏览文件 @
215ed793
...
...
@@ -97,6 +97,11 @@ template("test_unittest") {
#libs += [ "//${root_out_dir}/${test_lib_dir}/libdlopen_dso.so" ]
}
if (target_name == "dlclose_reset") {
ldflags += [ "-rdynamic" ]
#libs += [ "//${root_out_dir}/${test_lib_dir}/libdlclose_reset_dso.so" ]
}
if (target_name == "tls_align") {
ldflags += [ "-Wl,-rpath=src/functional" ]
libs += [ "//${root_out_dir}/${test_lib_dir}/libtls_align_dso.so" ]
...
...
musl_src.gni
浏览文件 @
215ed793
...
...
@@ -1829,6 +1829,7 @@ musl_src_porting_file = [
"include/sys/capability.h",
"include/sys/socket.h",
"include/sys/sysinfo.h",
"src/internal/dynlink.h",
"include/unistd.h",
"src/internal/pthread_impl.h",
"src/internal/syscall.h",
...
...
@@ -1844,4 +1845,6 @@ musl_src_porting_file = [
"src/sched/sched_getscheduler.c",
"src/thread/arm/clone.s",
"src/thread/arm/syscall_cp.s",
"src/ldso/dlclose.c",
"ldso/dynlink.c",
]
porting/linux/user/ldso/dynlink.c
0 → 100644
浏览文件 @
215ed793
此差异已折叠。
点击以展开。
porting/linux/user/src/internal/dynlink.h
0 → 100644
浏览文件 @
215ed793
#ifndef _INTERNAL_RELOC_H
#define _INTERNAL_RELOC_H
#include <features.h>
#include <elf.h>
#include <stdint.h>
#include <stddef.h>
#include <stdarg.h>
#if UINTPTR_MAX == 0xffffffff
typedef
Elf32_Ehdr
Ehdr
;
typedef
Elf32_Phdr
Phdr
;
typedef
Elf32_Sym
Sym
;
#define R_TYPE(x) ((x)&255)
#define R_SYM(x) ((x)>>8)
#define R_INFO ELF32_R_INFO
#else
typedef
Elf64_Ehdr
Ehdr
;
typedef
Elf64_Phdr
Phdr
;
typedef
Elf64_Sym
Sym
;
#define R_TYPE(x) ((x)&0x7fffffff)
#define R_SYM(x) ((x)>>32)
#define R_INFO ELF64_R_INFO
#endif
/* These enum constants provide unmatchable default values for
* any relocation type the arch does not use. */
enum
{
REL_NONE
=
0
,
REL_SYMBOLIC
=
-
100
,
REL_USYMBOLIC
,
REL_GOT
,
REL_PLT
,
REL_RELATIVE
,
REL_OFFSET
,
REL_OFFSET32
,
REL_COPY
,
REL_SYM_OR_REL
,
REL_DTPMOD
,
REL_DTPOFF
,
REL_TPOFF
,
REL_TPOFF_NEG
,
REL_TLSDESC
,
REL_FUNCDESC
,
REL_FUNCDESC_VAL
,
};
struct
fdpic_loadseg
{
uintptr_t
addr
,
p_vaddr
,
p_memsz
;
};
struct
fdpic_loadmap
{
unsigned
short
version
,
nsegs
;
struct
fdpic_loadseg
segs
[];
};
struct
fdpic_dummy_loadmap
{
unsigned
short
version
,
nsegs
;
struct
fdpic_loadseg
segs
[
1
];
};
#include "reloc.h"
#ifndef FDPIC_CONSTDISP_FLAG
#define FDPIC_CONSTDISP_FLAG 0
#endif
#ifndef DL_FDPIC
#define DL_FDPIC 0
#endif
#ifndef DL_NOMMU_SUPPORT
#define DL_NOMMU_SUPPORT 0
#endif
#if !DL_FDPIC
#define IS_RELATIVE(x,s) ( \
(R_TYPE(x) == REL_RELATIVE) || \
(R_TYPE(x) == REL_SYM_OR_REL && !R_SYM(x)) )
#else
#define IS_RELATIVE(x,s) ( ( \
(R_TYPE(x) == REL_FUNCDESC_VAL) || \
(R_TYPE(x) == REL_SYMBOLIC) ) \
&& (((s)[R_SYM(x)].st_info & 0xf) == STT_SECTION) )
#endif
#ifndef NEED_MIPS_GOT_RELOCS
#define NEED_MIPS_GOT_RELOCS 0
#endif
#ifndef DT_DEBUG_INDIRECT
#define DT_DEBUG_INDIRECT 0
#endif
#define AUX_CNT 32
#define DYN_CNT 32
typedef
void
(
*
stage2_func
)(
unsigned
char
*
,
size_t
*
);
hidden
void
*
__dlsym
(
void
*
restrict
,
const
char
*
restrict
,
void
*
restrict
);
hidden
int
__dlclose
(
void
*
p
);
hidden
void
__dl_seterr
(
const
char
*
,
...);
hidden
int
__dl_invalid_handle
(
void
*
);
hidden
void
__dl_vseterr
(
const
char
*
,
va_list
);
hidden
ptrdiff_t
__tlsdesc_static
(),
__tlsdesc_dynamic
();
#endif
porting/linux/user/src/ldso/dlclose.c
0 → 100644
浏览文件 @
215ed793
#include <dlfcn.h>
#include "dynlink.h"
static
int
dummy
(
void
*
p
)
{
return
__dl_invalid_handle
(
p
);
}
weak_alias
(
dummy
,
__dlclose
);
int
dlclose
(
void
*
p
)
{
return
__dlclose
(
p
);
}
scripts/runtest_Windows.bat
浏览文件 @
215ed793
...
...
@@ -57,12 +57,14 @@ for /F %%i in ('dir %TESTDIR% /S /B') do (
)
@REM 动态库传输
hdc
file
send
%DYNLIB%
\libdlopen_dso.so
%REMOTE%
/functional/libdlopen
_dso.so
hdc
file
send
%DYNLIB%
\libdlclose_reset_dso.so
%REMOTE%
/functional/libdlclose
_reset_dso.so
hdc
file
send
%DYNLIB%
\libtls_align_dso.so
%REMOTE%
/functional/libtls
_align_dso.so
hdc
file
send
%DYNLIB%
\libtls_init_dso.so
%REMOTE%
/functional/libtls
_init_dso.so
hdc
file
send
%DYNLIB%
\libtls_get_new
-dtv
_dso.so
%REMOTE%
/regression/libtls
_get_new
-dtv
_dso.so
@REM 修改动态库权限
hdc
shell
chmod
a
+x
%REMOTE%
/functional/libdlopen
_dso.so
hdc
shell
chmod
a
+x
%REMOTE%
/functional/libdlclose
_reset_dso.so
hdc
shell
chmod
a
+x
%REMOTE%
/functional/libtls
_align_dso.so
hdc
shell
chmod
a
+x
%REMOTE%
/functional/libtls
_init_dso.so
hdc
shell
chmod
a
+x
%REMOTE%
/regression/libtls
_get_new
-dtv
_dso.so
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录