Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
75fa87b7
T
Third Party Musl
项目概览
OpenHarmony
/
Third Party Musl
1 年多 前同步成功
通知
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看板
未验证
提交
75fa87b7
编写于
7月 19, 2023
作者:
O
openharmony_ci
提交者:
Gitee
7月 19, 2023
浏览文件
操作
浏览文件
下载
差异文件
!973 Add linker log
Merge pull request !973 from yinchuang/add_linker_log
上级
cea704b5
5aa165b0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
55 addition
and
41 deletion
+55
-41
porting/linux/user/ldso/cfi.c
porting/linux/user/ldso/cfi.c
+22
-27
porting/linux/user/ldso/dynlink.c
porting/linux/user/ldso/dynlink.c
+17
-8
porting/linux/user/ldso/ld_log.h
porting/linux/user/ldso/ld_log.h
+1
-3
porting/linux/user/src/thread/pthread_create.c
porting/linux/user/src/thread/pthread_create.c
+15
-3
未找到文件。
porting/linux/user/ldso/cfi.c
浏览文件 @
75fa87b7
...
...
@@ -184,12 +184,9 @@ static uintptr_t get_cfi_check_addr(uint16_t value, void* func_ptr)
static
inline
void
cfi_slowpath_common
(
uint64_t
call_site_type_id
,
void
*
func_ptr
,
void
*
diag_data
)
{
LD_LOGI
(
"[CFI] [%{public}s] func_ptr[%{public}p] !
\n
"
,
__FUNCTION__
,
func_ptr
);
uint16_t
value
=
sv_invalid
;
if
(
func_ptr
==
NULL
)
{
LD_LOGE
(
"[CFI] [%{public}s] func_ptr is NULL!
\n
"
,
__FUNCTION__
);
return
;
}
...
...
@@ -214,7 +211,11 @@ static inline void cfi_slowpath_common(uint64_t call_site_type_id, void *func_pt
}
else
{
value
=
*
((
uint16_t
*
)(
cfi_shadow_start
+
offset
));
}
LD_LOGI
(
"[CFI] [%{public}s] the value is 0x%{public}x!
\n
"
,
__FUNCTION__
,
value
);
LD_LOGD
(
"[CFI] [%{public}s] called from %{public}s to %{public}s func_ptr:0x%{public}p shadow value:%{public}d diag_data:0x%{public}p call_site_type_id[%{public}p.
\n
"
,
__FUNCTION__
,
((
struct
dso
*
)
addr2dso
((
size_t
)
__builtin_return_address
(
0
)))
->
name
,
((
struct
dso
*
)
addr2dso
((
size_t
)
func_ptr
))
->
name
,
func_ptr
,
value
,
diag_data
,
call_site_type_id
);
struct
dso
*
dso
=
NULL
;
switch
(
value
)
...
...
@@ -232,7 +233,7 @@ static inline void cfi_slowpath_common(uint64_t call_site_type_id, void *func_pt
LD_LOGE
(
"[CFI] [%{public}s] can not find the dso!
\n
"
,
__FUNCTION__
);
__builtin_trap
();
}
LD_LOG
I
(
"[CFI] [%{public}s] dso name[%{public}s]!
\n
"
,
__FUNCTION__
,
dso
->
name
);
LD_LOG
D
(
"[CFI] [%{public}s] dso name[%{public}s]!
\n
"
,
__FUNCTION__
,
dso
->
name
);
struct
symdef
cfi_check_sym
=
find_cfi_check_sym
(
dso
);
if
(
!
cfi_check_sym
.
sym
)
{
...
...
@@ -255,7 +256,7 @@ static inline void cfi_slowpath_common(uint64_t call_site_type_id, void *func_pt
int
init_cfi_shadow
(
struct
dso
*
dso_list
,
struct
dso
*
ldso
)
{
LD_LOG
I
(
"[CFI] [%{public}s] start!
\n
"
,
__FUNCTION__
);
LD_LOG
D
(
"[CFI] [%{public}s] start!
\n
"
,
__FUNCTION__
);
if
(
dso_list
==
NULL
)
{
LD_LOGW
(
"[CFI] [%{public}s] has null param!
\n
"
,
__FUNCTION__
);
...
...
@@ -271,8 +272,6 @@ int init_cfi_shadow(struct dso *dso_list, struct dso *ldso)
int
map_dso_to_cfi_shadow
(
struct
dso
*
dso
)
{
LD_LOGI
(
"[CFI] [%{public}s] start!
\n
"
,
__FUNCTION__
);
bool
has_cfi_check
=
false
;
if
(
dso
==
NULL
)
{
...
...
@@ -285,7 +284,7 @@ int map_dso_to_cfi_shadow(struct dso *dso)
/* Find __cfi_check symbol in dso list */
for
(
struct
dso
*
p
=
dso
;
p
;
p
=
p
->
next
)
{
if
(
find_cfi_check_sym
(
p
).
sym
)
{
LD_LOG
I
(
"[CFI] [%{public}s] find __cfi_check function in dso %{public}s!
\n
"
,
__FUNCTION__
,
p
->
name
);
LD_LOG
D
(
"[CFI] [%{public}s] find __cfi_check function in dso %{public}s!
\n
"
,
__FUNCTION__
,
p
->
name
);
has_cfi_check
=
true
;
break
;
}
...
...
@@ -296,13 +295,11 @@ int map_dso_to_cfi_shadow(struct dso *dso)
LD_LOGE
(
"[CFI] [%{public}s] create cfi shadow failed!
\n
"
,
__FUNCTION__
);
return
CFI_FAILED
;
}
LD_LOGD
(
"[CFI] [%{public}s] add_dso_to_cfi_shadow with dso_list_head!
\n
"
,
__FUNCTION__
);
add_dso_to_cfi_shadow
(
dso_list_head
);
prctl
(
PR_SET_VMA
,
PR_SET_VMA_ANON_NAME
,
cfi_shadow_start
,
shadow_size
,
"cfi_shadow:musl"
);
}
/* If the cfi shadow exists, map the current dso and its dependents to it. */
}
else
{
LD_LOGD
(
"[CFI] [%{public}s] add_dso_to_cfi_shadow with dso!
\n
"
,
__FUNCTION__
);
add_dso_to_cfi_shadow
(
dso
);
prctl
(
PR_SET_VMA
,
PR_SET_VMA_ANON_NAME
,
cfi_shadow_start
,
shadow_size
,
"cfi_shadow:musl"
);
}
...
...
@@ -312,14 +309,12 @@ int map_dso_to_cfi_shadow(struct dso *dso)
void
unmap_dso_from_cfi_shadow
(
struct
dso
*
dso
)
{
LD_LOGD
(
"[CFI] [%{public}s] start!
\n
"
,
__FUNCTION__
);
if
(
dso
==
NULL
)
{
LD_LOG
E
(
"[CFI] [%{public}s] has null param!
\n
"
,
__FUNCTION__
);
LD_LOG
D
(
"[CFI] [%{public}s] has null param!
\n
"
,
__FUNCTION__
);
return
;
}
LD_LOG
I
(
"[CFI] [%{public}s] unmap dso %{public}s from shadow!
\n
"
,
__FUNCTION__
,
dso
->
name
);
LD_LOG
D
(
"[CFI] [%{public}s] unmap dso %{public}s from shadow!
\n
"
,
__FUNCTION__
,
dso
->
name
);
if
(
cfi_shadow_start
==
NULL
)
return
;
...
...
@@ -354,17 +349,16 @@ static int create_cfi_shadow(void)
}
cfi_shadow_start
=
(
char
*
)
mmap_addr
;
LD_LOG
I
(
"[CFI] [%{public}s] the cfi_shadow_start addr is %{public}p!
\n
"
,
__FUNCTION__
,
cfi_shadow_start
);
LD_LOG
D
(
"[CFI] [%{public}s] the cfi_shadow_start addr is %{public}p!
\n
"
,
__FUNCTION__
,
cfi_shadow_start
);
return
CFI_SUCCESS
;
}
static
int
add_dso_to_cfi_shadow
(
struct
dso
*
dso
)
{
LD_LOGI
(
"[CFI] [%{public}s] start!
\n
"
,
__FUNCTION__
);
LD_LOGD
(
"[CFI] [%{public}s] start with %{public}s !
\n
"
,
__FUNCTION__
,
dso
->
name
);
for
(
struct
dso
*
p
=
dso
;
p
;
p
=
p
->
next
)
{
LD_LOG
I
(
"[CFI] [%{public}s] start to deal with dso %{public}s
!
\n
"
,
__FUNCTION__
,
p
->
name
);
LD_LOG
D
(
"[CFI] [%{public}s] adding %{public}s to cfi shadow
!
\n
"
,
__FUNCTION__
,
p
->
name
);
if
(
p
->
map
==
0
||
p
->
map_len
==
0
)
{
LD_LOGW
(
"[CFI] [%{public}s] the dso has no data! map[%{public}p] map_len[0x%{public}x]
\n
"
,
__FUNCTION__
,
p
->
map
,
p
->
map_len
);
...
...
@@ -372,43 +366,44 @@ static int add_dso_to_cfi_shadow(struct dso *dso)
}
if
(
p
->
is_mapped_to_shadow
==
true
)
{
LD_LOGW
(
"[CFI] [%{public}s]
the dso is already in shadow!
\n
"
,
__FUNCTION__
);
LD_LOGW
(
"[CFI] [%{public}s]
%{public}s is already in shadow!
\n
"
,
__FUNCTION__
,
p
->
name
);
continue
;
}
struct
symdef
cfi_check_sym
=
find_cfi_check_sym
(
p
);
/* If the dso doesn't have __cfi_check(), set it's shadow value unchecked. */
if
(
!
cfi_check_sym
.
sym
)
{
LD_LOG
I
(
"[CFI] [%{public}s] the dso has no __cfi_check()!
\n
"
,
__FUNCTION__
);
LD_LOG
D
(
"[CFI] [%{public}s] %{public}s has no __cfi_check()!
\n
"
,
__FUNCTION__
,
p
->
name
);
if
(
fill_shadow_value_to_shadow
(
p
->
map
,
p
->
map
+
p
->
map_len
,
0
,
sv_uncheck
)
==
CFI_FAILED
)
{
LD_LOGE
(
"[CFI] [%{public}s] add dso to cfi shadow failed!
\n
"
,
__FUNCTION__
);
return
CFI_FAILED
;
}
/* If the dso has __cfi_check(), set it's shadow value valid. */
}
else
{
LD_LOG
I
(
"[CFI] [%{public}s] the dso has __cfi_check()!
\n
"
,
__FUNCTION__
);
LD_LOG
D
(
"[CFI] [%{public}s] %{public}s has __cfi_check()!
\n
"
,
__FUNCTION__
,
p
->
name
);
uintptr_t
end
=
p
->
map
+
p
->
map_len
;
uintptr_t
cfi_check
=
LADDR
(
cfi_check_sym
.
dso
,
cfi_check_sym
.
sym
->
st_value
);
if
(
cfi_check
==
0
)
{
LD_LOGE
(
"[CFI] [%{public}s]
the dso has null cfi_check func!
\n
"
,
__FUNCTION__
);
LD_LOGE
(
"[CFI] [%{public}s]
%{public}s has null cfi_check func!
\n
"
,
__FUNCTION__
,
p
->
name
);
return
CFI_FAILED
;
}
if
(
fill_shadow_value_to_shadow
(
p
->
map
,
end
,
cfi_check
,
sv_valid_min
)
==
CFI_FAILED
)
{
LD_LOGE
(
"[CFI] [%{public}s] add
dso to cfi shadow failed!
\n
"
,
__FUNCTION__
);
LD_LOGE
(
"[CFI] [%{public}s] add
%{public}s to cfi shadow failed!
\n
"
,
__FUNCTION__
,
p
->
name
);
return
CFI_FAILED
;
}
}
p
->
is_mapped_to_shadow
=
true
;
LD_LOG
I
(
"[CFI] [%{public}s] finish to deal with dso %{public}s!
\n
"
,
__FUNCTION__
,
p
->
name
);
LD_LOG
D
(
"[CFI] [%{public}s] add %{public}s to cfi shadow succeed.
\n
"
,
__FUNCTION__
,
p
->
name
);
}
LD_LOGD
(
"[CFI] [%{public}s] %{public}s done.
\n
"
,
__FUNCTION__
,
dso
->
name
);
return
CFI_SUCCESS
;
}
static
int
fill_shadow_value_to_shadow
(
uintptr_t
begin
,
uintptr_t
end
,
uintptr_t
cfi_check
,
uint16_t
type
)
{
LD_LOG
I
(
"[CFI] [%{public}s] begin[%{public}x] end[%{public}x] cfi_check[%{public}x] type[%{public}x]!
\n
"
,
LD_LOG
D
(
"[CFI] [%{public}s] begin[%{public}x] end[%{public}x] cfi_check[%{public}x] type[%{public}x]!
\n
"
,
__FUNCTION__
,
begin
,
end
,
cfi_check
,
type
);
/* To ensure the atomicity of the CFI shadow operation, we create a temp_shadow, write the shadow value to
...
...
@@ -445,7 +440,7 @@ static int fill_shadow_value_to_shadow(uintptr_t begin, uintptr_t end, uintptr_t
uint16_t
shadow_value_begin
=
((
begin
+
shadow_alignment
-
cfi_check
)
>>
cfi_check_granularity
)
+
sv_valid_min
;
#endif
LD_LOG
I
(
"[CFI] [%{public}s] shadow_value_begin is 0x%{public}x!
\n
"
,
__FUNCTION__
,
shadow_value_begin
);
LD_LOG
D
(
"[CFI] [%{public}s] shadow_value_begin is 0x%{public}x!
\n
"
,
__FUNCTION__
,
shadow_value_begin
);
uint16_t
shadow_value_step
=
1
<<
(
shadow_granularity
-
cfi_check_granularity
);
uint16_t
shadow_value
=
shadow_value_begin
;
...
...
porting/linux/user/ldso/dynlink.c
浏览文件 @
75fa87b7
...
...
@@ -2305,10 +2305,8 @@ static void do_android_relocs(struct dso *p, size_t dt_name, size_t dt_size)
}
if
(
dt_name
==
DT_ANDROID_REL
)
{
LD_LOGI
(
"do_android_relocs REL %{public}x %{public}x"
,
rel
[
0
],
rel
[
1
]);
do_relocs
(
p
,
rel
,
sizeof
(
size_t
)
*
2
,
2
);
}
else
{
LD_LOGI
(
"do_android_relocs RELA %{public}x %{public}x %{public}x"
,
rel
[
0
],
rel
[
1
],
rel
[
2
]);
do_relocs
(
p
,
rel
,
sizeof
(
size_t
)
*
3
,
3
);
}
}
...
...
@@ -3429,11 +3427,9 @@ void *dlopen(const char *file, int mode)
void
dlns_init
(
Dl_namespace
*
dlns
,
const
char
*
name
)
{
if
(
!
dlns
)
{
LD_LOGE
(
"dlns_init dlns is null."
);
return
;
}
if
(
!
name
)
{
LD_LOGE
(
"dlns_init name is null."
);
dlns
->
name
[
0
]
=
0
;
return
;
}
...
...
@@ -3695,20 +3691,25 @@ static int dlclose_impl(struct dso *p)
return
-
1
;
if
(
!
p
->
by_dlopen
)
{
error
(
"Library %s is no
t loaded by dlopen"
,
p
->
name
);
LD_LOGD
(
"dlclose skip unload %{public}s because so isn'
t loaded by dlopen"
,
p
->
name
);
return
-
1
;
}
/* dso is marked as RTLD_NODELETE library, do nothing here. */
if
((
p
->
flags
&
DSO_FLAGS_NODELETE
)
!=
0
)
{
LD_LOGD
(
"dlclose skip unload %{public}s because flags is RTLD_NODELETE"
,
p
->
name
);
return
0
;
}
if
(
--
(
p
->
nr_dlopen
)
>
0
)
if
(
--
(
p
->
nr_dlopen
)
>
0
)
{
LD_LOGD
(
"dlclose skip unload %{public}s because nr_dlopen=%{public}d > 0"
,
p
->
name
,
p
->
nr_dlopen
);
return
0
;
}
if
(
p
->
parents_count
>
0
)
if
(
p
->
parents_count
>
0
)
{
LD_LOGD
(
"dlclose skip unload %{public}s because parents_count=%{public}d > 0"
,
p
->
name
,
p
->
parents_count
);
return
0
;
}
trace_marker_reset
();
trace_marker_begin
(
HITRACE_TAG_MUSL
,
"dlclose"
,
p
->
name
);
...
...
@@ -3790,6 +3791,7 @@ static int dlclose_impl(struct dso *p)
}
if
(
p
->
deps
!=
no_deps
)
free
(
p
->
deps
);
LD_LOGD
(
"dlclose unloading %{public}s @%{public}p"
,
p
->
name
,
p
);
unmap_library
(
p
);
if
(
p
->
parents
)
{
...
...
@@ -4846,6 +4848,8 @@ static bool load_library_header(struct loadtask *task)
task
->
p
=
find_library_by_name
(
name
,
namespace
,
check_inherited
);
if
(
task
->
p
)
{
task
->
isloaded
=
true
;
LD_LOGD
(
"find_library_by_name(name=%{public}s ns=%{public}s) already loaded by %{public}s in %{public}s namespace "
,
name
,
namespace
->
ns_name
,
task
->
p
->
name
,
task
->
p
->
namespace
->
ns_name
);
return
true
;
}
if
(
strlen
(
name
)
>
NAME_MAX
)
{
...
...
@@ -4912,6 +4916,8 @@ static bool load_library_header(struct loadtask *task)
close
(
task
->
fd
);
task
->
fd
=
-
1
;
task
->
isloaded
=
true
;
LD_LOGD
(
"find_library_by_fstat(name=%{public}s ns=%{public}s) already loaded by %{public}s in %{public}s namespace "
,
name
,
namespace
->
ns_name
,
task
->
p
->
name
,
task
->
p
->
namespace
->
ns_name
);
return
true
;
}
...
...
@@ -4979,6 +4985,7 @@ static bool load_library_header(struct loadtask *task)
static
void
task_load_library
(
struct
loadtask
*
task
,
struct
reserved_address_params
*
reserved_params
)
{
LD_LOGD
(
"load_library loading ns=%{public}s name=%{public}s by_dlopen=%{public}d"
,
task
->
namespace
->
ns_name
,
task
->
p
->
name
,
runtime
);
bool
map
=
noload
?
0
:
task_map_library
(
task
,
reserved_params
);
close
(
task
->
fd
);
task
->
fd
=
-
1
;
...
...
@@ -5070,7 +5077,9 @@ static void preload_direct_deps(struct dso *p, ns_t *namespace, struct loadtasks
if
(
p
->
dynv
[
i
]
!=
DT_NEEDED
)
{
continue
;
}
struct
loadtask
*
task
=
create_loadtask
(
p
->
strings
+
p
->
dynv
[
i
+
1
],
p
,
namespace
,
true
);
const
char
*
dtneed_name
=
p
->
strings
+
p
->
dynv
[
i
+
1
];
LD_LOGD
(
"load_library %{public}s adding DT_NEEDED task %{public}s namespace(%{public}s)"
,
p
->
name
,
dtneed_name
,
namespace
->
ns_name
);
struct
loadtask
*
task
=
create_loadtask
(
dtneed_name
,
p
,
namespace
,
true
);
if
(
!
task
)
{
LD_LOGE
(
"Error loading dependencies %{public}s : create load task failed"
,
p
->
name
);
error
(
"Error loading dependencies for %s : create load task failed"
,
p
->
name
);
...
...
porting/linux/user/ldso/ld_log.h
浏览文件 @
75fa87b7
...
...
@@ -37,9 +37,7 @@ hidden void ld_log_reset();
hidden
bool
is_dlclose_debug_enable
();
#if ((LD_LOG_LEVEL & LD_LOG_ERROR) && (defined(OHOS_ENABLE_PARAMETER) || defined(ENABLE_MUSL_LOG)))
#define LD_LOGE(...) if (get_ld_log_enable()) { \
(void)HiLogAdapterPrint(MUSL_LOG_TYPE, LOG_ERROR, MUSL_LOG_DOMAIN, LD_LOG_TAG, __VA_ARGS__); \
}
#define LD_LOGE(...) (void)HiLogAdapterPrint(MUSL_LOG_TYPE, LOG_ERROR, MUSL_LOG_DOMAIN, LD_LOG_TAG, __VA_ARGS__);
#else
#define LD_LOGE(...)
#endif
...
...
porting/linux/user/src/thread/pthread_create.c
浏览文件 @
75fa87b7
#define _GNU_SOURCE
#define ANON_STACK_NAME_SIZE 50
#include "musl_log.h"
#include "pthread_impl.h"
#include "stdio_impl.h"
#include "libc.h"
...
...
@@ -336,7 +337,10 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
pthread_attr_t
attr
=
{
0
};
sigset_t
set
;
if
(
!
libc
.
can_do_threads
)
return
ENOSYS
;
if
(
!
libc
.
can_do_threads
)
{
MUSL_LOGE
(
"pthread_create: can't do threads, err: %{public}s"
,
strerror
(
errno
));
return
ENOSYS
;
}
self
=
__pthread_self
();
if
(
!
libc
.
threaded
)
{
for
(
FILE
*
f
=*
__ofl_lock
();
f
;
f
=
f
->
next
)
...
...
@@ -383,15 +387,22 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
if
(
!
tsd
)
{
if
(
guard
)
{
map
=
__mmap
(
0
,
size
,
PROT_NONE
,
MAP_PRIVATE
|
MAP_ANON
,
-
1
,
0
);
if
(
map
==
MAP_FAILED
)
goto
fail
;
if
(
map
==
MAP_FAILED
)
{
MUSL_LOGE
(
"pthread_create: mmap PROT_NONE failed, err:%{public}s"
,
strerror
(
errno
));
goto
fail
;
}
if
(
__mprotect
(
map
+
guard
,
size
-
guard
,
PROT_READ
|
PROT_WRITE
)
&&
errno
!=
ENOSYS
)
{
MUSL_LOGE
(
"pthread_create: mprotect failed, err:%{public}s"
,
strerror
(
errno
));
__munmap
(
map
,
size
);
goto
fail
;
}
}
else
{
map
=
__mmap
(
0
,
size
,
PROT_READ
|
PROT_WRITE
,
MAP_PRIVATE
|
MAP_ANON
,
-
1
,
0
);
if
(
map
==
MAP_FAILED
)
goto
fail
;
if
(
map
==
MAP_FAILED
)
{
MUSL_LOGE
(
"pthread_create: mmap PROT_READ|PROT_WRITE failed, err:%{public}s"
,
strerror
(
errno
));
goto
fail
;
}
}
tsd
=
map
+
size
-
__pthread_tsd_size
;
if
(
!
stack
)
{
...
...
@@ -476,6 +487,7 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
if
(
ret
<
0
)
{
if
(
map
)
__munmap
(
map
,
size
);
MUSL_LOGE
(
"pthread_create: ret:%{public}d, err:%{public}s"
,
ret
,
strerror
(
errno
));
return
-
ret
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录