0

I am making modification on the kernel files. I want to load one function if it is a 32 bit architecture or load another function if it is a 64 bit architecture. Is it possible to get architecture info in the kernel during build time and load different functions based on it. In which location is the architecture info stored or from where to get the info? Thanks.

  • 1
    Related: is my linux ARM 32 or 64 bit? – cas Aug 5 '17 at 1:23
  • Think further beyond the architecture, and while you parse the uname output (as cas suggested) maybe you need addional info, e.g kernel version, distro, etc.. – ilansch Aug 5 '17 at 7:36
2

If you are compiling on the target machine itself, uname -m will give you what you want on most machines. e.g. on my 64-bit desktop machine:

$ uname -m
x86_64

This won't explicitly tell you whether the machine is 64 or 32 bit. It's just a string that you will have to interpret (e.g. with a series of if/then statements or a case statement).

Here's a (very crude) example in sh:

machine=$(uname -m)
bits=0

case "$machine" in
       *64*) bits=64 ;;
  *[3-6]86*) bits=32 ;;
    *armv7*) bits=32 ;;  # replace with a pattern to match your 32-bit android cpu
    *armv8*) bits=64 ;;  # replace with a pattern to match your 64-bit android cpu
esac

[ "$bits" = 0 ] && echo "Unknown machine type" && exit 1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.