Given the following C++ code 'mini.cpp':
#include "iostream"
using namespace std;
int main() {
cout << "Hello World" << endl;
return 0;
}
and the compiler command:
g++ -o hello mini.cpp
the result of
mimetype hello
is
hello: application/x-sharedlib
How do I get 'application/x-application' as a mime type?
I'm using gcc 6.2.0 on Kubuntu.
gcc doesn't set the mime type.
mimetypeguesses the appropriate mime type based on the contents of the file. For ELF files (most compiled binaries and shared libraries), the header contains a fielde_typewhich identifies its type. If it isET_DYN, thenmimetypewill treat it as a shared library.By default, gcc/ld will produce binaries which set
e_typetoET_EXEC, which get detected asapplication/x-executable. When the command-line option-pieis used, a position-independent executable is created, which may, like shared libraries, be loaded at different addresses and still work. Because this works so much like a shared library, to avoid too many changes to the loader, such binaries get marked asET_DYN, even though they can be executed directly.Some Linux distributions, yours included, have set
-pieas the default. It's still possible to override this with-no-pie, but the fact that the mime type is misdetected should not be seen as a bug, and unless you know what you're doing, you shouldn't override it.-pieallows for some extra security protections that are fundamentally incompatible with-no-pie.