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

get_isa() in get-stack.sh does not handle all possible outputs of uname -m #5792

Closed
mpilgrem opened this issue Jul 24, 2022 · 8 comments · Fixed by #5805
Closed

get_isa() in get-stack.sh does not handle all possible outputs of uname -m #5792

mpilgrem opened this issue Jul 24, 2022 · 8 comments · Fixed by #5805

Comments

@mpilgrem
Copy link
Member

get_isa() in get-stack.sh is as follows:

# determines the the CPU's instruction set
get_isa() {
  if uname -m | grep -Eq 'armv[78]l?' ; then
    echo arm
  elif uname -m | grep -q aarch64 ; then
    echo aarch64
  else
    echo x86
  fi
}

get_isa() is used by is_x86_64() which, in turn, is used by do_distro() (called in the 'Linux' limb of do_os()).

get_isa() assumes that if the output of uname -m (the machine hardware name) is not armv6l, armv7l or aarch64 then it is x86_64 (or x86). However, this Wikipedia table indicates that other values are possible when uname -s (the kernel name) is Linux, including arm6l, sparc64,ppc64,i686,ppc,k1om, and 'mips.

It has been suggested that this is a 'bug waiting to happen'.

@HallowedDust5
Copy link
Contributor

I think I can do this.

@HallowedDust5
Copy link
Contributor

What exactly does the function return? Does it return the instruction set of the given cpu as provided by uname -m or does it return something else? What I'm asking is, what is the relation between the value returned by get_isa() and the value given by uname -m?

@mpilgrem
Copy link
Member Author

I am not a 'scripter', but I think if you start at do_os() and 'work backwards', you will see the use made of the result of get_isa(). I think get_isa() needs to 'fail' if uname -m yields an unsupported machine architecture.

@HallowedDust5
Copy link
Contributor

Oh that makes sense, thanks

@HallowedDust5
Copy link
Contributor

Does the following code look good enough?

get_isa() {
  if uname -m | grep -Eq 'armv[78]l?' ; then
    echo arm
  elif uname -m | grep -q aarch64 ; then
    echo aarch64
  elif uname -m | grep -q x86 ; then
    echo x86
  else
    die "${uname -m} is not a supported instruction set"
  fi
}

I would have gone through and done checks for all the possible outputs for uname -m but it seemed like those checks wouldn't really do anything because I don't know where to check for what ISAs are supported.

@HallowedDust5
Copy link
Contributor

I didn't open up a PR for this code because I wanted to make sure it's actually addressing the issue.

@mpilgrem
Copy link
Member Author

It looks good to me, but with one question. I don't know much about sh scripts, but I read this: https://stackoverflow.com/questions/27472540/difference-between-and-in-bash. Is ${uname -m} what you need? Or is it $(uname -m)?

@HallowedDust5
Copy link
Contributor

That's my Javascript coming out. Oops.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants