summaryrefslogtreecommitdiff
path: root/elf
diff options
context:
space:
mode:
authorCarlos O'Donell <carlos@systemhalted.org>2015-02-17 19:25:01 -0500
committerCarlos O'Donell <carlos@systemhalted.org>2015-02-17 19:29:15 -0500
commit8a35c3fe122d49ba76dff815b3537affb5a50b45 (patch)
tree37fba229a2f0557ffdfd8ee431f499888aea4a16 /elf
parent1a2325c06cf309d1d8b4aafcfb1a3d43905baf9b (diff)
Use alignment macros, pagesize and powerof2.
We are replacing all of the bespoke alignment code with ALIGN_UP, ALIGN_DOWN, PTR_ALIGN_UP, and PTR_ALIGN_DOWN. This cleans up malloc/malloc.c, malloc/arena.c, and elf/dl-reloc.c. It also makes all the code consistently use pagesize, and powerof2 as required. Code size is reduced with the removal of precomputed pagemask, and use of pagesize instead. No measurable difference in performance. No regressions on x86_64.
Diffstat (limited to 'elf')
-rw-r--r--elf/dl-reloc.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/elf/dl-reloc.c b/elf/dl-reloc.c
index 9c2705d539..b72287d984 100644
--- a/elf/dl-reloc.c
+++ b/elf/dl-reloc.c
@@ -26,6 +26,7 @@
#include <sys/types.h>
#include <_itoa.h>
#include "dynamic-link.h"
+#include <libc-internal.h>
/* Statistics function. */
#ifdef SHARED
@@ -74,9 +75,9 @@ _dl_try_allocate_static_tls (struct link_map *map)
map->l_tls_offset = GL(dl_tls_static_used) = offset;
#elif TLS_DTV_AT_TP
/* dl_tls_static_used includes the TCB at the beginning. */
- size_t offset = (((GL(dl_tls_static_used)
- - map->l_tls_firstbyte_offset
- + map->l_tls_align - 1) & -map->l_tls_align)
+ size_t offset = (ALIGN_UP(GL(dl_tls_static_used)
+ - map->l_tls_firstbyte_offset,
+ map->l_tls_align)
+ map->l_tls_firstbyte_offset);
size_t used = offset + map->l_tls_blocksize;
@@ -201,11 +202,10 @@ _dl_relocate_object (struct link_map *l, struct r_scope_elem *scope[],
struct textrels *newp;
newp = (struct textrels *) alloca (sizeof (*newp));
- newp->len = (((ph->p_vaddr + ph->p_memsz + GLRO(dl_pagesize) - 1)
- & ~(GLRO(dl_pagesize) - 1))
- - (ph->p_vaddr & ~(GLRO(dl_pagesize) - 1)));
- newp->start = ((ph->p_vaddr & ~(GLRO(dl_pagesize) - 1))
- + (caddr_t) l->l_addr);
+ newp->len = ALIGN_UP (ph->p_vaddr + ph->p_memsz, GLRO(dl_pagesize))
+ - ALIGN_DOWN (ph->p_vaddr, GLRO(dl_pagesize));
+ newp->start = PTR_ALIGN_DOWN (ph->p_vaddr, GLRO(dl_pagesize))
+ + (caddr_t) l->l_addr;
if (__mprotect (newp->start, newp->len, PROT_READ|PROT_WRITE) < 0)
{
@@ -324,11 +324,13 @@ _dl_relocate_object (struct link_map *l, struct r_scope_elem *scope[],
void internal_function
_dl_protect_relro (struct link_map *l)
{
- ElfW(Addr) start = ((l->l_addr + l->l_relro_addr)
- & ~(GLRO(dl_pagesize) - 1));
- ElfW(Addr) end = ((l->l_addr + l->l_relro_addr + l->l_relro_size)
- & ~(GLRO(dl_pagesize) - 1));
-
+ ElfW(Addr) start = ALIGN_DOWN((l->l_addr
+ + l->l_relro_addr),
+ GLRO(dl_pagesize));
+ ElfW(Addr) end = ALIGN_DOWN((l->l_addr
+ + l->l_relro_addr
+ + l->l_relro_size),
+ GLRO(dl_pagesize));
if (start != end
&& __mprotect ((void *) start, end - start, PROT_READ) < 0)
{