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

PAGE_SIZE is not portable #11

Closed
vext01 opened this issue Jan 26, 2017 · 5 comments
Closed

PAGE_SIZE is not portable #11

vext01 opened this issue Jan 26, 2017 · 5 comments

Comments

@vext01
Copy link
Contributor

vext01 commented Jan 26, 2017

After working around #10, I get the following compilation error on OpenBSD:

[  3%] Building C object libipt/CMakeFiles/libipt.dir/src/posix/pt_section_posix.c.o
cd /home/edd/research/hwt_experiment/processor-trace/build/libipt && /usr/bin/cc  -DFEATURE_THREADS -DPT_VERSION_BUILD=0 -DPT_VERSION_EXT=\"\" -DPT_VERSION_MAJOR=1 -DPT_VERSION_MINOR=6 -Dlibipt_EXPORTS -I/home/edd/research/hwt_experiment/processor-trace/include -I/home/edd/research/hwt_experiment/processor-trace/build/libipt/include -I/home/edd/research/hwt_experiment/processor-trace/include/posix -I/home/edd/research/hwt_experiment/processor-trace/libipt/internal/include -I/home/edd/research/hwt_experiment/processor-trace/libipt/internal/include/posix  -std=c99 -fvisibility=hidden -fPIC   -o CMakeFiles/libipt.dir/src/posix/pt_section_posix.c.o   -c /home/edd/research/hwt_experiment/processor-trace/libipt/src/posix/pt_section_posix.c
/home/edd/research/hwt_experiment/processor-trace/libipt/src/posix/pt_section_posix.c: In function 'pt_sec_posix_map':
/home/edd/research/hwt_experiment/processor-trace/libipt/src/posix/pt_section_posix.c:114: error: 'PAGE_SIZE' undeclared (first use in this function)
/home/edd/research/hwt_experiment/processor-trace/libipt/src/posix/pt_section_posix.c:114: error: (Each undeclared identifier is reported only once
/home/edd/research/hwt_experiment/processor-trace/libipt/src/posix/pt_section_posix.c:114: error: for each function it appears in.)

Arguably the page size should not be a compile time constant, as this means traces from different machines with different page sizes can not be decoded.

@markus-metzger
Copy link
Contributor

Thanks for reporting this.

The PAGE_SIZE macro is defined in <sys/user.h> on Linux - but apparently not on OpenBSD. A more portable version should be sysconf(_SC_PAGESIZE). I hope this is available on OpenBSD, as well.

Let me set up an OpenBSD system to check.

@vext01
Copy link
Contributor Author

vext01 commented Jan 27, 2017

Hi Markus,

On my OpenBSD amd64 laptop:

unistd.h
180:#define     _SC_PAGESIZE            28
181:#define     _SC_PAGE_SIZE           _SC_PAGESIZE    /* 1170 compatibility */

So you could probably fix the compilation error in this way, yes. But is the page-size baked into the PT trace somehow? If so, you'd probably want a runtime switch?

Thanks

@markus-metzger
Copy link
Contributor

Hi Edd,

The page size is used to align mmap() mapped memory. Libipt maps code sections from binary files to decode instructions. This should be OK; sysconf(_SC_PAGESIZE) is also used in the example on the mmap(2) man page.

@vext01
Copy link
Contributor Author

vext01 commented Jan 30, 2017

Hi Markus, just found that unistd.h defines getpagesize() on both Linux and OpenBSD.

@vext01 vext01 changed the title PAGE_SIZE is a compile time constant PAGE_SIZE is not portable Jan 30, 2017
markus-metzger added a commit that referenced this issue Feb 2, 2017
This fixes #11.

Change-Id: I45a62dbb10ea84e5e408532ff996b2028d85e93b
Signed-off-by: Markus Metzger <markus.t.metzger@intel.com>
@vext01
Copy link
Contributor Author

vext01 commented Feb 3, 2017

Thanks!

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

No branches or pull requests

2 participants