madmonkey1907 / hakchi

GNU General Public License v3.0
144 stars 36 forks source link

Build error on macOS - error: taking address of packed member of class or structure may result in an unaligned pointer #27

Open franktinsley opened 6 years ago

franktinsley commented 6 years ago

When I try to build on macOS I get the following errors:

gcc -o mkbootimg.o -ffunction-sections -O3 -c mkbootimg.c -I. -Werror
mkbootimg.c:284:41: error: taking address of packed member 'kernel_size' of class or structure 'boot_img_hdr' may result in an unaligned pointer
      value [-Werror,-Waddress-of-packed-member]
    kernel_data = load_file(kernel_fn, &hdr.kernel_size);
                                        ^~~~~~~~~~~~~~~
mkbootimg.c:294:47: error: taking address of packed member 'ramdisk_size' of class or structure 'boot_img_hdr' may result in an unaligned pointer
      value [-Werror,-Waddress-of-packed-member]
        ramdisk_data = load_file(ramdisk_fn, &hdr.ramdisk_size);
                                              ^~~~~~~~~~~~~~~~
mkbootimg.c:302:45: error: taking address of packed member 'second_size' of class or structure 'boot_img_hdr' may result in an unaligned pointer
      value [-Werror,-Waddress-of-packed-member]
        second_data = load_file(second_fn, &hdr.second_size);
                                            ^~~~~~~~~~~~~~~
mkbootimg.c:310:37: error: taking address of packed member 'dt_size' of class or structure 'boot_img_hdr' may result in an unaligned pointer value
      [-Werror,-Waddress-of-packed-member]
        dt_data = load_file(dt_fn, &hdr.dt_size);
                                    ^~~~~~~~~~~
4 errors generated.
make[1]: *** [mkbootimg.o] Error 1
make: *** [3rdparty/mkbootimg/mkbootimg] Error 2

Any tips? Thanks.

kirill3333 commented 6 years ago

got the same issue on last MacOSX version looks like problem appears when script tries to make mkbootimg

franktinsley commented 6 years ago

@kirill3333 ah, is that script something I can edit? Maybe we just need to point it at different stuff?

kirill3333 commented 6 years ago

@franktinsley I don't know waiting to @madmonkey1907 answer probably he tried to make it on MacOS X

franktinsley commented 6 years ago

I think he mentioned earlier that he doesn't have a mac.

kirill3333 commented 6 years ago

@franktinsley could you try to make this repo on your mac https://github.com/osm0sis/mkbootimg for me I get the same issue

franktinsley commented 6 years ago

@kirill3333 here's what I got:

make -C libmincrypt
gcc -o dsa_sig.o -ffunction-sections -O3 -c dsa_sig.c -I..
gcc -o p256.o -ffunction-sections -O3 -c p256.c -I..
gcc -o p256_ec.o -ffunction-sections -O3 -c p256_ec.c -I..
gcc -o p256_ecdsa.o -ffunction-sections -O3 -c p256_ecdsa.c -I..
gcc -o rsa.o -ffunction-sections -O3 -c rsa.c -I..
gcc -o sha.o -ffunction-sections -O3 -c sha.c -I..
gcc -o sha256.o -ffunction-sections -O3 -c sha256.c -I..
ar rc libmincrypt.a dsa_sig.o p256.o p256_ec.o p256_ecdsa.o rsa.o sha.o sha256.o
cp libmincrypt.a ..
gcc -o mkbootimg.o -ffunction-sections -O3 -c mkbootimg.c -I. -Werror
mkbootimg.c:381:41: error: taking address of packed member 'kernel_size' of
      class or structure 'boot_img_hdr' may result in an unaligned pointer value
      [-Werror,-Waddress-of-packed-member]
    kernel_data = load_file(kernel_fn, &hdr.kernel_size);
                                        ^~~~~~~~~~~~~~~
mkbootimg.c:391:47: error: taking address of packed member 'ramdisk_size' of
      class or structure 'boot_img_hdr' may result in an unaligned pointer value
      [-Werror,-Waddress-of-packed-member]
        ramdisk_data = load_file(ramdisk_fn, &hdr.ramdisk_size);
                                              ^~~~~~~~~~~~~~~~
mkbootimg.c:399:45: error: taking address of packed member 'second_size' of
      class or structure 'boot_img_hdr' may result in an unaligned pointer value
      [-Werror,-Waddress-of-packed-member]
        second_data = load_file(second_fn, &hdr.second_size);
                                            ^~~~~~~~~~~~~~~
mkbootimg.c:407:37: error: taking address of packed member 'dt_size' of class or
      structure 'boot_img_hdr' may result in an unaligned pointer value
      [-Werror,-Waddress-of-packed-member]
        dt_data = load_file(dt_fn, &hdr.dt_size);
                                    ^~~~~~~~~~~
4 errors generated.
make: *** [mkbootimg.o] Error 1
ComancheAk commented 6 years ago

Same issue here

gcc -o mkbootimg.o -ffunction-sections -O3 -c mkbootimg.c -I. -Werror
mkbootimg.c:284:41: error: taking address of packed member 'kernel_size' of
      class or structure 'boot_img_hdr' may result in an unaligned pointer value
      [-Werror,-Waddress-of-packed-member]
    kernel_data = load_file(kernel_fn, &hdr.kernel_size);
                                        ^~~~~~~~~~~~~~~
mkbootimg.c:294:47: error: taking address of packed member 'ramdisk_size' of
      class or structure 'boot_img_hdr' may result in an unaligned pointer value
      [-Werror,-Waddress-of-packed-member]
        ramdisk_data = load_file(ramdisk_fn, &hdr.ramdisk_size);
                                              ^~~~~~~~~~~~~~~~
mkbootimg.c:302:45: error: taking address of packed member 'second_size' of
      class or structure 'boot_img_hdr' may result in an unaligned pointer value
      [-Werror,-Waddress-of-packed-member]
        second_data = load_file(second_fn, &hdr.second_size);
                                            ^~~~~~~~~~~~~~~
mkbootimg.c:310:37: error: taking address of packed member 'dt_size' of class or
      structure 'boot_img_hdr' may result in an unaligned pointer value
      [-Werror,-Waddress-of-packed-member]
        dt_data = load_file(dt_fn, &hdr.dt_size);
                                    ^~~~~~~~~~~
4 errors generated.
make[1]: *** [mkbootimg.o] Error 1
make: *** [3rdparty/mkbootimg/mkbootimg] Error 2
madmonkey1907 commented 6 years ago

I do not have mac. -Werror,-Waddress-of-packed-member either remove -Werror from gcc/clang options, or add -Wno-address-of-packed-member, or -Wno-error afaik, macos never run on any architectures where this would be a problem, and none of this code is performance-critical.

DeadlySystem commented 6 years ago

...or run it in a container, compiling on Debian: https://github.com/DeadlySystem/ninspect/tree/master/docker-hakchi This is tested under Windows, I don't see why it wouldn't work on Mac though if you have a suitable X Server.

franktinsley commented 6 years ago

@madmonkey1907 I'm super new to compiling in command line. What commands should I enter or what lines in which file should I edit? Thanks for the help man.

maestun commented 6 years ago

I haven't tested the code, run at your own risk.

You can modify the 3rdparty/mkbootimg/bootimg.h file: remove " attribute ((packed))" at line 64. I also added this to the hakchi-gui.pro file, just before QMAKE_CFLAGS (or it doesnt compile on my machine): LIBS += -framework CoreFoundation

franktinsley commented 6 years ago

It built!!

isage commented 6 years ago

Can't we just use https://github.com/CyanogenMod/android_system_core/tree/cm-14.1/mkbootimg instead?

madmonkey1907 commented 6 years ago

you certainly can, if don't have aversion to snakes as I do :)

isage commented 6 years ago

Oh, i do. But it's either that or pulling mkbootimg sources to hakchi repo and patching.

gingerbeardman commented 6 years ago

@franktinsley how did you get on? Any progress since building successfully?

franktinsley commented 6 years ago

@gingerbeardman I got it to build but haven’t been had much time to go further. It looks like a lot more work than I was repaired for.

gingerbeardman commented 6 years ago

I built this but all I see is "knock, knock" in the gui

tried in standard mode (power on, light on) and flashing mode (power on, light off)

what am i missing?

madmonkey1907 commented 6 years ago

it only works in 'flashing mode'. what does it show after 'dump uboot' is pressed?

paraita commented 6 years ago

Removing the -Werror flag fixed that problem for me.