Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aarch64: vdso symbols #1292

Merged
merged 6 commits into from
Jul 9, 2024

Conversation

chl337
Copy link
Collaborator

@chl337 chl337 commented May 26, 2024

TODO:

  • replace hard-coded vdso-symbol value with query
  • refactor
  • rebase
  • test on x86 machine for sanity

@shrik3
Copy link
Collaborator

shrik3 commented May 26, 2024

  1. x86 and aarch64 have different function (symbol) names, and not necessarily the same ones, e.g. the x86 build has
    Symbol table '.symtab' contains 17 entries:
    Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS vdso.cc
     2: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS vdso_time.cc
     3: ffffffffff701110   168 FUNC    LOCAL  DEFAULT   11 _ZN4vdso13ClockR[...]
     4: ffffffffff7011c0   168 FUNC    LOCAL  DEFAULT   11 _ZN4vdso14ClockM[...]
     5: ffffffffff7004a8   272 OBJECT  LOCAL  HIDDEN     9 _DYNAMIC
     6: ffffffffff700000     0 NOTYPE  LOCAL  DEFAULT  ABS VDSO_PRELINK
     7: ffffffffff6ff000     0 NOTYPE  LOCAL  DEFAULT  ABS _params
     8: 0000000000000000     0 OBJECT  GLOBAL DEFAULT  ABS LINUX_2.6
     9: ffffffffff701100    10 FUNC    WEAK   DEFAULT   11 getcpu
    10: ffffffffff701100    10 FUNC    GLOBAL DEFAULT   11 __vdso_getcpu
    11: ffffffffff7010d0    34 FUNC    WEAK   DEFAULT   11 time
    12: ffffffffff7010d0    34 FUNC    GLOBAL DEFAULT   11 __vdso_time
    13: ffffffffff701060    97 FUNC    WEAK   DEFAULT   11 gettimeofday
    14: ffffffffff701060    97 FUNC    GLOBAL DEFAULT   11 __vdso_gettimeofday
    15: ffffffffff701020    56 FUNC    WEAK   DEFAULT   11 clock_gettime
    16: ffffffffff701020    56 FUNC    GLOBAL DEFAULT   11 __vdso_clock_gettime
    
  2. since aarch64 mandates vdso for signals to work, consider using panic if the symbols are not found.

qlib/kernel/loader/vdso.rs Outdated Show resolved Hide resolved
@chl337
Copy link
Collaborator Author

chl337 commented May 26, 2024

  1. x86 and aarch64 have different function (symbol) names, and not necessarily the same ones, e.g. the x86 build has
    Symbol table '.symtab' contains 17 entries: Num: Value Size Type Bind Vis Ndx Name 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND 1: 0000000000000000 0 FILE LOCAL DEFAULT ABS vdso.cc 2: 0000000000000000 0 FILE LOCAL DEFAULT ABS vdso_time.cc 3: ffffffffff701110 168 FUNC LOCAL DEFAULT 11 _ZN4vdso13ClockR[...] 4: ffffffffff7011c0 168 FUNC LOCAL DEFAULT 11 _ZN4vdso14ClockM[...] 5: ffffffffff7004a8 272 OBJECT LOCAL HIDDEN 9 _DYNAMIC 6: ffffffffff700000 0 NOTYPE LOCAL DEFAULT ABS VDSO_PRELINK 7: ffffffffff6ff000 0 NOTYPE LOCAL DEFAULT ABS _params 8: 0000000000000000 0 OBJECT GLOBAL DEFAULT ABS LINUX_2.6 9: ffffffffff701100 10 FUNC WEAK DEFAULT 11 getcpu 10: ffffffffff701100 10 FUNC GLOBAL DEFAULT 11 __vdso_getcpu 11: ffffffffff7010d0 34 FUNC WEAK DEFAULT 11 time 12: ffffffffff7010d0 34 FUNC GLOBAL DEFAULT 11 __vdso_time 13: ffffffffff701060 97 FUNC WEAK DEFAULT 11 gettimeofday 14: ffffffffff701060 97 FUNC GLOBAL DEFAULT 11 __vdso_gettimeofday 15: ffffffffff701020 56 FUNC WEAK DEFAULT 11 clock_gettime 16: ffffffffff701020 56 FUNC GLOBAL DEFAULT 11 __vdso_clock_gettime

    1. since aarch64 mandates vdso for signals to work, consider using panic if the symbols are not found.

I am aware, please note this is not the final version:

TODO:
     refactor

qlib/kernel/loader/vdso.rs Outdated Show resolved Hide resolved

#[cfg(target_arch = "x86_64")]
impl VdsoArchSymbols {
pub fn set_symbols_page_offset(&mut self, elf_file: &ElfFile, symbol_table: &[Entry64]) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is assuming that vdso is one single page right? Perhaps add a memory limit in the linker script to make sure of that?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping. could you also do this? perhaps in another PR.
if the vdso object goes beyond (not likely but not impossible) one page, the parser code may go wrong.

e.g. https://sourceware.org/binutils/docs/ld/MEMORY.html

qlib/kernel/loader/vdso.rs Outdated Show resolved Hide resolved
qlib/kernel/loader/vdso.rs Outdated Show resolved Hide resolved

pub fn set_symbols_page_offset(&mut self, elf_file: &ElfFile, symbol_table: &[Entry64]) {
let mut found_symbols = 0;
for sym in 0..Self::TOTAL_SYMBOLS {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

qkernel already uses the hashbrown, a KV store would make life easier here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, too much underling complexity for such a minimal case...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the complexity of using a hashmap, when the alternative is a nested for loop with strcmp

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it is done only once, for an unnoticeable small number of elements, with unnoticeable short names as keys and very simple logic for to mess it up.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not just once. Every time a signal happens the kernel for loop through the list and strcmp up to 4 times to find the sigreturn symbol. Not a big difference with only 4 elements though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not just once.

Sorry, I didn't specify that I meant storing.

up to 4 times to find the sigreturn symbol.

As we are (for now) only concerned with sigreturn,
it could be placed at [0].

... but again:

Not a big difference with only 4 elements though.

P.S. I just learned what 'nit' means :)

@chl337 chl337 changed the title [WIP]aarch64: vdso symbols aarch64: vdso symbols Jun 4, 2024
let mut _vdso_symbols: VdsoArchSymbols = Default::default();
_vdso_symbols.set_symbols_page_offset(&elf_file, symbols);
self.vdso_symbols = Some(_vdso_symbols);
} else if cfg!(target_arch = "aarch64") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is cfg! macro compile time?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, and it was not meant so.

Copy link
Collaborator

@shrik3 shrik3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from a distance perhaps some commits could be squashed, otherwise looks fine to me.

@QuarkContainer
Copy link
Owner

@chl337 what's the current status for the PR and could we merge this?

@chl337
Copy link
Collaborator Author

chl337 commented Jul 8, 2024

@chl337 what's the current status for the PR and could we merge this?

Just for sanity, please test it on your machine first. Then it can be merged.

@QuarkContainer
Copy link
Owner

@chl337 it is tested in my side. No issue. Can you merge it or I can do?

@chl337
Copy link
Collaborator Author

chl337 commented Jul 8, 2024

@chl337 it is tested in my side. No issue. Can you merge it or I can do?

Then please proceed.

@QuarkContainer QuarkContainer merged commit 44e7fdf into QuarkContainer:main Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants