Compile script fails with gcc6 compiler (Debian testing)

Since the new gcc6 version (6.2.0) the compile script fails with the following message:

/var/lib/dkms/nvidia/367.44/build/nvidia/nv-frontend.c:1:0: error: code
model <b>kernel does not support PIC mode</b>

I have also tried the lastest driver (367.57), two different kernels (4.7 and 4.8) and with and w/o DKMS support, same error. I could solve the problem by adding these lines to the /usr/src/linux-headers-4.x.x.x-common/Makefile file.

KBUILD_CFLAGS += $(call cc-option, -fno-pie)
KBUILD_CFLAGS += $(call cc-option, -no-pie)
KBUILD_AFLAGS += $(call cc-option, -fno-pie)
KBUILD_CPPFLAGS += $(call cc-option, -fno-pie)

Source: Re: Update to Sid, and cannot compile Nvidia module; PIC mode?

Is there a way to change the NVIDIA-Linux-x86_64-xxx.xx.run script instead of the system wide makefile?

Hello,

I encounter the same problem in similar environment:
Debian testing
kernel – 4.7.0-1 and above
gcc – 6.2.0-13
nvidia version – Linux-x86_64-367.57

After adding the options suggested by ripat, the module compiles, but on loading it says: Unknown symbol mcount (err 0).

Any help would be welcome.

“-fno-pie” can be passed by using environment variables as follows;

export KCPPFLAGS=“-fno-pie”
export CPPFLAGS=“$KCPPFLAGS”
sh ./NVIDIA-Linux-x86_64-xxx.xx.run

FYI, this is a known issue and already fixed in linux-4.8.11.
https://lkml.org/lkml/2016/11/24/494
https://www.kernel.org/pub/linux/kernel/v4.x/ChangeLog-4.8.11