tinyos / nesc

Master nesc repository
GNU General Public License v2.0
100 stars 53 forks source link

Nondeterminism in nesc output #36

Open mstewartgallus opened 8 years ago

mstewartgallus commented 8 years ago

There are two cases.

When function declarations do not have argument names then nondeterministic names will be generated for them like typedef int (*__compar_fn_t)(const void *arg_0x2aeff645d6e0, const void *arg_0x2aeff645d9b8);.

When templated instances are used then instance parameters for functions can also have nondeterministic names.

This is bad for reproducible builds although I think as of now it can only really effect debug information.

cire831 commented 8 years ago

can you please be more specific?

what exactly is non-deterministic?

mstewartgallus commented 8 years ago

The function declaration arguments seem to have names generated from program pointers to memory. Such pointers are usually nondeterministic because of things like ASLR.

But anyway, the simplest way to reproduce the problem is to run the command nescc -conly -S -fnesc-cfile=old.c Source.nc && nescc -conly -S -fnesc-cfile=new.c Source.nc for some source Source.nc and then compare the output files with diff or a similar utility.

cire831 commented 8 years ago

what is ASLR?

On Tue, Dec 22, 2015 at 1:29 PM, Steven Stewart-Gallus < notifications@github.com> wrote:

The function declaration arguments seem to have names generated from program pointers to memory. Such pointers are usually nondeterministic because of things like ASLR.

But anyway, the simplest way to reproduce the problem is to run the command nescc -conly -S -fnesc-cfile=old.c Source.nc && nescc -conly -S -fnesc-cfile=new.c Source.nc and then compare the output files with diff or a similar utility.

— Reply to this email directly or view it on GitHub https://github.com/tinyos/nesc/issues/36#issuecomment-166734361.

Eric B. Decker Senior (over 50 :-) Researcher

mstewartgallus commented 8 years ago

ASLR is short for Address Space Layout Randomization and is a security feature in modern operating systems.

When the library code for malloc or similar allocates memory it ultimately needs to defer to the OS and use a system call such as sbrk or mmap to map memory into the process. With ASLR the OS can return a random memory block for certain mmap requests instead of a deterministic one. As well, carefully written program loaders let mmap and ASLR map libraries and position independent executables into random locations so pointers to data in library and executable code may not be deterministic.

cire831 commented 8 years ago

okay. thanks for the def

so why does any of this matter?

On Tue, Dec 22, 2015 at 8:19 PM, Steven Stewart-Gallus < notifications@github.com> wrote:

ASLR is short for Address Space Layout Randomization

When the library code for malloc or similar allocates memory it ultimately needs to defer to the OS and use a system call such as sbrk or mmap to map memory into the process. With ASLR the OS can return a random memory block for certain mmap requests instead of a deterministic one. As well, carefully written program loaders libraries let mmap and ASLR map libraries and position independent executables into random locations, so pointers to data in library and executable code may not be deterministic.

— Reply to this email directly or view it on GitHub https://github.com/tinyos/nesc/issues/36#issuecomment-166799811.

Eric B. Decker Senior (over 50 :-) Researcher

mstewartgallus commented 8 years ago

Reproducible builds have a number of uses: see https://reproducible-builds.org/

I personally would like reproducible builds so that if I decide to distribute partially compiled code (nesc code translated to C code but the C code not compiled to object code) that someone else could independently compile and create the C code to be sure I wasn't pulling any funny business.

phil-levis commented 8 years ago

Steven,

I'd suggest contacting David Gay (dgay42), since he wrote 99% of the nesC compiler. He can at the very least point you at the bit of code that generates those argument names so you can suggest something more deterministic.