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

Prevent absolute paths being embedded in binaries #499

Open
ptheywood opened this issue Apr 8, 2021 · 3 comments
Open

Prevent absolute paths being embedded in binaries #499

ptheywood opened this issue Apr 8, 2021 · 3 comments

Comments

@ptheywood
Copy link
Member

ptheywood commented Apr 8, 2021

Debug info and the use of __FILE__ embed absolute paths into binary files, which is probably bad if we end up distributing any pre-compiled files.

GCC/clang support -fdebug-prefix-map=OLD=NEW as a way of changing paths in debug info.

More recent GCC / Clang also support modifying the behaviour of __FILE__ via -fmacro-prefix-map=OLD=NEW. -ffile-prefix-map=OLD=NEW can be used to set both these options.

source

I am unsure if NVCC / MSVC will have comparible options (I've not yet looked). This might include use of -lineinfo/-G in NVCC.
Worth checking to see if Cmake has a feature for these.

Cmake may also need some changins making, as it embeds some paths into the binary by default.

  • Some comments on the nvidia developer forums suggest NVCC does not support this (or atleast didn't?)
  • MSVC doesn't appear to support a similar option (source)
    • Although there is an undocumented experimental flag which might be relevant (in the future?) experimental:deterministic

For GCC Clang versions which support it, rough cmake would be:

target_compile_options(target PUBLIC "-ffile-prefix-map=${CMAKE_SOURCE_DIR}=.")
@ptheywood
Copy link
Member Author

This is probably relevant prior to any binary releases? #514

@ptheywood
Copy link
Member Author

ptheywood commented Jul 21, 2021

Rob suggested that we could just prune the __FILE__ value from the exception printing so that it starts with include/flamepgu?, Not as nice as preventing the strings from being embedded, but should work on compilers which do not support the use of __FILE__ and relative paths.

Will also need to consider exceptions trhwon from src/flamegpu too

@ptheywood
Copy link
Member Author

ptheywood commented Aug 4, 2021

Using -ffile-prefix-map where appropriate on gcc /clang does appear to work, and works for hots compilation of NVCC (but probably not for device code?)

# in game of life main.cu::main()
printf("FILE LINE %s:%d\n", __FILE__, __LINE__);
# before 
FILE LINE /home/ptheywood/code/flamegpu/FLAMEGPU2/examples/game_of_life/src/main.cu:35
# after 
FILE LINE ./examples/game_of_life/src/main.cu:35

Although i'm not super keen on it starting with the . but I'm not sure what the alt would be.

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

No branches or pull requests

1 participant