ソースを参照

Fix tls tests for dynamic linker

* load TLS segment for executable - while we can skip PT_LOAD for executable,
  we still have to load TLS segment.
* set TCB address based on if elf is position independent
Mateusz Tabaka 4 年 前
コミット
eee9a80baa
2 ファイル変更12 行追加8 行削除
  1. 11 5
      src/ld_so/linker.rs
  2. 1 3
      tests/Makefile

+ 11 - 5
src/ld_so/linker.rs

@@ -604,9 +604,6 @@ impl Linker {
             } else {
                 false
             };
-            if same_elf {
-                continue;
-            }
             let object = match lib.objects.get(*elf_name) {
                 Some(some) => some,
                 None => continue,
@@ -627,6 +624,9 @@ impl Linker {
 
                 match ph.p_type {
                     program_header::PT_LOAD => {
+                        if same_elf {
+                            continue;
+                        }
                         let obj_data = {
                             let range = ph.file_range();
                             match object.get(range.clone()) {
@@ -671,9 +671,15 @@ impl Linker {
                         } else {
                             ph.p_memsz
                         } as usize;
-
+                        let ptr = unsafe {
+                            if is_pie_enabled(elf) {
+                                mmap.as_ptr().add(ph.p_vaddr as usize)
+                            } else {
+                                ph.p_vaddr as *const u8
+                            }
+                        };
                         let mut tcb_master = Master {
-                            ptr: unsafe { mmap.as_ptr().add(ph.p_vaddr as usize - base_addr) },
+                            ptr: ptr,
                             len: ph.p_filesz as usize,
                             offset: tls_size - valign,
                         };

+ 1 - 3
tests/Makefile

@@ -73,6 +73,7 @@ EXPECT_NAMES=\
 	time/mktime \
 	time/strftime \
 	time/time \
+	tls \
 	unistd/access \
 	unistd/brk \
 	unistd/dup \
@@ -121,9 +122,6 @@ STATIC_ONLY_NAMES=\
 # need to call fini in ld_so's _start
 STATIC_ONLY_NAMES+=\
 	destructor \
-# comparison issue
-STATIC_ONLY_NAMES+=\
-	tls \
 # issues with linking optarg, optind etc.
 STATIC_ONLY_NAMES+=\
 	unistd/getopt \