mirror of https://gitee.com/Nocallback/glibc.git
Browse Source
We can't relocate entries in dynamic section if it is readonly: 1. Add a l_ld_readonly field to struct link_map to indicate if dynamic section is readonly and set it based on p_flags of PT_DYNAMIC segment. 2. Replace DL_RO_DYN_SECTION with dl_relocate_ld to decide if dynamic section should be relocated. 3. Remove DL_RO_DYN_TEMP_CNT. 4. Don't use a static dynamic section to make readonly dynamic section in vDSO writable. 5. Remove the temp argument from elf_get_dynamic_info. This fixes BZ #28340. Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>maskray/x86-mpx
16 changed files with 198 additions and 41 deletions
@ -0,0 +1,19 @@ |
|||
/* Test case for DSO with readonly dynamic section.
|
|||
Copyright (C) 2021 Free Software Foundation, Inc. |
|||
This file is part of the GNU C Library. |
|||
|
|||
The GNU C Library is free software; you can redistribute it and/or |
|||
modify it under the terms of the GNU Lesser General Public |
|||
License as published by the Free Software Foundation; either |
|||
version 2.1 of the License, or (at your option) any later version. |
|||
|
|||
The GNU C Library is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|||
Lesser General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU Lesser General Public |
|||
License along with the GNU C Library; if not, see |
|||
<https://www.gnu.org/licenses/>. */
|
|||
|
|||
int foo = -1; |
|||
@ -0,0 +1,16 @@ |
|||
SECTIONS |
|||
{ |
|||
. = SIZEOF_HEADERS; |
|||
.dynamic : { *(.dynamic) } :text :dynamic |
|||
.rodata : { *(.data*) *(.bss*) } :text |
|||
/DISCARD/ : { |
|||
*(.note.gnu.property) |
|||
} |
|||
.note : { *(.note.*) } :text :note |
|||
} |
|||
PHDRS |
|||
{ |
|||
text PT_LOAD FLAGS(5) FILEHDR PHDRS; |
|||
dynamic PT_DYNAMIC FLAGS(4); |
|||
note PT_NOTE FLAGS(4); |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
/* Test case for DSO with readonly dynamic section.
|
|||
Copyright (C) 2021 Free Software Foundation, Inc. |
|||
This file is part of the GNU C Library. |
|||
|
|||
The GNU C Library is free software; you can redistribute it and/or |
|||
modify it under the terms of the GNU Lesser General Public |
|||
License as published by the Free Software Foundation; either |
|||
version 2.1 of the License, or (at your option) any later version. |
|||
|
|||
The GNU C Library is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|||
Lesser General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU Lesser General Public |
|||
License along with the GNU C Library; if not, see |
|||
<https://www.gnu.org/licenses/>. */
|
|||
|
|||
#include <support/check.h> |
|||
#include <support/test-driver.h> |
|||
|
|||
extern int foo; |
|||
|
|||
static int |
|||
do_test (void) |
|||
{ |
|||
TEST_COMPARE (foo, -1); |
|||
return 0; |
|||
} |
|||
|
|||
#include <support/test-driver.c> |
|||
@ -0,0 +1,32 @@ |
|||
/* Check if dynamic section should be relocated. Generic version.
|
|||
Copyright (C) 2021 Free Software Foundation, Inc. |
|||
This file is part of the GNU C Library. |
|||
|
|||
The GNU C Library is free software; you can redistribute it and/or |
|||
modify it under the terms of the GNU Lesser General Public |
|||
License as published by the Free Software Foundation; either |
|||
version 2.1 of the License, or (at your option) any later version. |
|||
|
|||
The GNU C Library is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|||
Lesser General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU Lesser General Public |
|||
License along with the GNU C Library; if not, see |
|||
<https://www.gnu.org/licenses/>. */
|
|||
|
|||
#ifndef _DL_RELOCATE_LD_H |
|||
#define _DL_RELOCATE_LD_H |
|||
|
|||
/* Return true if dynamic section in the shared library L should be
|
|||
relocated. */ |
|||
|
|||
static inline bool |
|||
dl_relocate_ld (const struct link_map *l) |
|||
{ |
|||
/* Don't relocate dynamic section if it is readonly */ |
|||
return !l->l_ld_readonly; |
|||
} |
|||
|
|||
#endif /* _DL_RELOCATE_LD_H */ |
|||
@ -0,0 +1,32 @@ |
|||
/* Check if dynamic section should be relocated. MIPS version.
|
|||
Copyright (C) 2021 Free Software Foundation, Inc. |
|||
This file is part of the GNU C Library. |
|||
|
|||
The GNU C Library is free software; you can redistribute it and/or |
|||
modify it under the terms of the GNU Lesser General Public |
|||
License as published by the Free Software Foundation; either |
|||
version 2.1 of the License, or (at your option) any later version. |
|||
|
|||
The GNU C Library is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|||
Lesser General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU Lesser General Public |
|||
License along with the GNU C Library; if not, see |
|||
<https://www.gnu.org/licenses/>. */
|
|||
|
|||
#ifndef _DL_RELOCATE_LD_H |
|||
#define _DL_RELOCATE_LD_H |
|||
|
|||
/* Return true if dynamic section in the shared library L should be
|
|||
relocated. */ |
|||
|
|||
static inline bool |
|||
dl_relocate_ld (const struct link_map *l) |
|||
{ |
|||
/* Never relocate dynamic section. */ |
|||
return false; |
|||
} |
|||
|
|||
#endif /* _DL_RELOCATE_LD_H */ |
|||
@ -0,0 +1,32 @@ |
|||
/* Check if dynamic section should be relocated. RISC-V version.
|
|||
Copyright (C) 2021 Free Software Foundation, Inc. |
|||
This file is part of the GNU C Library. |
|||
|
|||
The GNU C Library is free software; you can redistribute it and/or |
|||
modify it under the terms of the GNU Lesser General Public |
|||
License as published by the Free Software Foundation; either |
|||
version 2.1 of the License, or (at your option) any later version. |
|||
|
|||
The GNU C Library is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|||
Lesser General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU Lesser General Public |
|||
License along with the GNU C Library; if not, see |
|||
<https://www.gnu.org/licenses/>. */
|
|||
|
|||
#ifndef _DL_RELOCATE_LD_H |
|||
#define _DL_RELOCATE_LD_H |
|||
|
|||
/* Return true if dynamic section in the shared library L should be
|
|||
relocated. */ |
|||
|
|||
static inline bool |
|||
dl_relocate_ld (const struct link_map *l) |
|||
{ |
|||
/* Never relocate dynamic section for ABI compatibility. */ |
|||
return false; |
|||
} |
|||
|
|||
#endif /* _DL_RELOCATE_LD_H */ |
|||
Loading…
Reference in new issue