libdyld: fixed symbol relocation #134

Merged
sb10q merged 1 commits from dyld-fix into master 2021-09-25 13:49:49 +08:00

Note that in libdyld/src/lib.rs #118-119, image pointer is already added to the symbol offset, so we do not need to add the pointer again. It is interesting that we never triggered this bug previously...

2ed2ffe417/src/libdyld/src/lib.rs (L118-L119)

    pub fn lookup(&self, name: &[u8]) -> Option<Elf32_Word> {
        let hash = elf_hash(name);
        let mut index = self.hash_bucket()[hash as usize % self.hash_bucket().len()] as usize;
        loop {
            if index == STN_UNDEF { return None }
            let sym = &self.symtab()[index];
            let sym_name_off = sym.st_name as usize;
            match self.strtab().get(sym_name_off..sym_name_off + name.len()) {
                Some(sym_name) if sym_name == name => {
                    if ELF32_ST_BIND(sym.st_info) & STB_GLOBAL == 0 {
                        return None
                    }
                    match sym.st_shndx {
                        SHN_UNDEF => return None,
                        SHN_ABS => return Some(self.image.ptr() as u32 + sym.st_value),
                        _ => return Some(self.image.ptr() as u32 + sym.st_value)
                    }
                }
                _ => (),
            }
            index = self.hash_chain()[index] as usize;
        }
    }
Note that in libdyld/src/lib.rs #118-119, image pointer is already added to the symbol offset, so we do not need to add the pointer again. It is interesting that we never triggered this bug previously... https://git.m-labs.hk/M-Labs/artiq-zynq/src/commit/2ed2ffe4178573afba9aece4855f74772feb0414/src/libdyld/src/lib.rs#L118-L119 ```rust pub fn lookup(&self, name: &[u8]) -> Option<Elf32_Word> { let hash = elf_hash(name); let mut index = self.hash_bucket()[hash as usize % self.hash_bucket().len()] as usize; loop { if index == STN_UNDEF { return None } let sym = &self.symtab()[index]; let sym_name_off = sym.st_name as usize; match self.strtab().get(sym_name_off..sym_name_off + name.len()) { Some(sym_name) if sym_name == name => { if ELF32_ST_BIND(sym.st_info) & STB_GLOBAL == 0 { return None } match sym.st_shndx { SHN_UNDEF => return None, SHN_ABS => return Some(self.image.ptr() as u32 + sym.st_value), _ => return Some(self.image.ptr() as u32 + sym.st_value) } } _ => (), } index = self.hash_chain()[index] as usize; } } ```
pca006132 added 1 commit 2021-09-25 11:40:07 +08:00
35250b3f56 libdyld: fixed symbol relocation
Note that in libdyld/src/lib.rs #117-118, image pointer is already added
to the symbol offset, so we do not need to add the pointer again

Tested with python -m unittest discover artiq.test.coredevice -v.

Tested with `python -m unittest discover artiq.test.coredevice -v`.
sb10q merged commit 35250b3f56 into master 2021-09-25 13:49:49 +08:00
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: M-Labs/artiq-zynq#134
There is no content yet.