Incorrect mmap behavior when assembly files in included in the projectWhy in mmap PROT_READ equals...
Is it now possible to undetectably cross the Arctic Ocean on ski/kayak?
Is fascism intrinsically violent?
Novel set in the future, children cannot change the class they are born into, one class is made uneducated by associating books with pain
Why does 1.1.1.1 not resolve archive.is?
Trying to add electrical outlets off of a junction box but the junction box has a lot more wires than Ive been shown so which ones to run it off?
What is a recommended strategy on exercises in a mathematical textbook at graduate level?
d-Menthol vs dl-menthol: Does an enantiomer and its racemic mixture have different melting points?
How to respond to "Why didn't you do a postdoc after your PhD?"
How does Firefox know my ISP login page?
Why are Starfleet vessels designed with nacelles so far away from the hull?
Do businesses save their customers' credit card information until the payment is finalized?
Why is beatboxing called 「ヒューマンビートボックス」?
Is there any restriction in entering the South American countries multiple times in one year?
Does every locally compact connected homogeneous metric space admit a vertex-transitive 'grid'?
How do I avoid and entry being shifted when using multirow and rowcolor at the same time?
How can demon technology be prevented from surpassing humans?
Why does b+=(4,) work and b = b + (4,) doesn't work when b is a list?
What is the fastest algorithm for finding the natural logarithm of a big number?
"Distance" vs "a distance"
"A tin of biscuits" vs "A biscuit tin"
Pass a bash variable to python script
Incorrect mmap behavior when assembly files in included in the project
What are the physical limits that determine a camera's flash sync speed?
If the music alphabet had more than 7 letters would octaves still sound like the same note?
Incorrect mmap behavior when assembly files in included in the project
Why in mmap PROT_READ equals PROT_EXECWhen should I use mmap for file access?When is assembly faster than C?libc.so has four segments mapped in a process, why?Mmap() an entire large fileFast resize of a mmap fileWhen would you use mmapCan code that is valid in both C and C++ produce different behavior when compiled in each language?strange mmap behavior
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}
I am banging my head into the wall with this.
In my project, when I'm allocating memory with mmap
the mapping (/proc/self/maps
) shows that it is an readable and executable region despite I requested only readable memory.
After looking into strace (which was looking good) and other debugging, I was able to identify the only thing that seems to avoid this strange problem: removing assembly files from the project and leaving only pure C. (what?!)
So here is my strange example, I am working on Ubunbtu 19.04 and default gcc.
If you compile the target executable with the ASM file (which is empty) then mmap
returns a readable and executable region, if you build without then it behave correctly. See the output of /proc/self/maps
which I have embedded in my example.
example.c
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
int main()
{
void* p;
p = mmap(NULL, 8192,PROT_READ,MAP_ANONYMOUS|MAP_PRIVATE,-1,0);
{
FILE *f;
char line[512], s_search[17];
snprintf(s_search,16,"%lx",(long)p);
f = fopen("/proc/self/maps","r");
while (fgets(line,512,f))
{
if (strstr(line,s_search)) fputs(line,stderr);
}
fclose(f);
}
return 0;
}
example.s: Is an empty file!
Outputs
With the ASM included version
VirtualBox:~/mechanics/build$ gcc example.c example.s -o example && ./example
7f78d6e08000-7f78d6e0a000 r-xp 00000000 00:00 0
Without the ASM included version
VirtualBox:~/mechanics/build$ gcc example.c -o example && ./example
7f1569296000-7f1569298000 r--p 00000000 00:00 0
c linux assembly mmap
add a comment
|
I am banging my head into the wall with this.
In my project, when I'm allocating memory with mmap
the mapping (/proc/self/maps
) shows that it is an readable and executable region despite I requested only readable memory.
After looking into strace (which was looking good) and other debugging, I was able to identify the only thing that seems to avoid this strange problem: removing assembly files from the project and leaving only pure C. (what?!)
So here is my strange example, I am working on Ubunbtu 19.04 and default gcc.
If you compile the target executable with the ASM file (which is empty) then mmap
returns a readable and executable region, if you build without then it behave correctly. See the output of /proc/self/maps
which I have embedded in my example.
example.c
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
int main()
{
void* p;
p = mmap(NULL, 8192,PROT_READ,MAP_ANONYMOUS|MAP_PRIVATE,-1,0);
{
FILE *f;
char line[512], s_search[17];
snprintf(s_search,16,"%lx",(long)p);
f = fopen("/proc/self/maps","r");
while (fgets(line,512,f))
{
if (strstr(line,s_search)) fputs(line,stderr);
}
fclose(f);
}
return 0;
}
example.s: Is an empty file!
Outputs
With the ASM included version
VirtualBox:~/mechanics/build$ gcc example.c example.s -o example && ./example
7f78d6e08000-7f78d6e0a000 r-xp 00000000 00:00 0
Without the ASM included version
VirtualBox:~/mechanics/build$ gcc example.c -o example && ./example
7f1569296000-7f1569298000 r--p 00000000 00:00 0
c linux assembly mmap
1
This is seriously weird.
– fuz
8 hours ago
2
I managed to reproduce this with just GCC (no CMake), so I edited the question to make the example more minimal.
– Joseph Sible
8 hours ago
Possibly related stackoverflow.com/questions/32730643/…
– Sami Kuhmonen
8 hours ago
You might be right, part of the he answer has to be around READ_IMPLIES_EXEC persona
– Benyamin Hirschberg
7 hours ago
add a comment
|
I am banging my head into the wall with this.
In my project, when I'm allocating memory with mmap
the mapping (/proc/self/maps
) shows that it is an readable and executable region despite I requested only readable memory.
After looking into strace (which was looking good) and other debugging, I was able to identify the only thing that seems to avoid this strange problem: removing assembly files from the project and leaving only pure C. (what?!)
So here is my strange example, I am working on Ubunbtu 19.04 and default gcc.
If you compile the target executable with the ASM file (which is empty) then mmap
returns a readable and executable region, if you build without then it behave correctly. See the output of /proc/self/maps
which I have embedded in my example.
example.c
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
int main()
{
void* p;
p = mmap(NULL, 8192,PROT_READ,MAP_ANONYMOUS|MAP_PRIVATE,-1,0);
{
FILE *f;
char line[512], s_search[17];
snprintf(s_search,16,"%lx",(long)p);
f = fopen("/proc/self/maps","r");
while (fgets(line,512,f))
{
if (strstr(line,s_search)) fputs(line,stderr);
}
fclose(f);
}
return 0;
}
example.s: Is an empty file!
Outputs
With the ASM included version
VirtualBox:~/mechanics/build$ gcc example.c example.s -o example && ./example
7f78d6e08000-7f78d6e0a000 r-xp 00000000 00:00 0
Without the ASM included version
VirtualBox:~/mechanics/build$ gcc example.c -o example && ./example
7f1569296000-7f1569298000 r--p 00000000 00:00 0
c linux assembly mmap
I am banging my head into the wall with this.
In my project, when I'm allocating memory with mmap
the mapping (/proc/self/maps
) shows that it is an readable and executable region despite I requested only readable memory.
After looking into strace (which was looking good) and other debugging, I was able to identify the only thing that seems to avoid this strange problem: removing assembly files from the project and leaving only pure C. (what?!)
So here is my strange example, I am working on Ubunbtu 19.04 and default gcc.
If you compile the target executable with the ASM file (which is empty) then mmap
returns a readable and executable region, if you build without then it behave correctly. See the output of /proc/self/maps
which I have embedded in my example.
example.c
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
int main()
{
void* p;
p = mmap(NULL, 8192,PROT_READ,MAP_ANONYMOUS|MAP_PRIVATE,-1,0);
{
FILE *f;
char line[512], s_search[17];
snprintf(s_search,16,"%lx",(long)p);
f = fopen("/proc/self/maps","r");
while (fgets(line,512,f))
{
if (strstr(line,s_search)) fputs(line,stderr);
}
fclose(f);
}
return 0;
}
example.s: Is an empty file!
Outputs
With the ASM included version
VirtualBox:~/mechanics/build$ gcc example.c example.s -o example && ./example
7f78d6e08000-7f78d6e0a000 r-xp 00000000 00:00 0
Without the ASM included version
VirtualBox:~/mechanics/build$ gcc example.c -o example && ./example
7f1569296000-7f1569298000 r--p 00000000 00:00 0
c linux assembly mmap
c linux assembly mmap
edited 8 hours ago
Joseph Sible
13.3k3 gold badges16 silver badges47 bronze badges
13.3k3 gold badges16 silver badges47 bronze badges
asked 8 hours ago
Benyamin HirschbergBenyamin Hirschberg
1456 bronze badges
1456 bronze badges
1
This is seriously weird.
– fuz
8 hours ago
2
I managed to reproduce this with just GCC (no CMake), so I edited the question to make the example more minimal.
– Joseph Sible
8 hours ago
Possibly related stackoverflow.com/questions/32730643/…
– Sami Kuhmonen
8 hours ago
You might be right, part of the he answer has to be around READ_IMPLIES_EXEC persona
– Benyamin Hirschberg
7 hours ago
add a comment
|
1
This is seriously weird.
– fuz
8 hours ago
2
I managed to reproduce this with just GCC (no CMake), so I edited the question to make the example more minimal.
– Joseph Sible
8 hours ago
Possibly related stackoverflow.com/questions/32730643/…
– Sami Kuhmonen
8 hours ago
You might be right, part of the he answer has to be around READ_IMPLIES_EXEC persona
– Benyamin Hirschberg
7 hours ago
1
1
This is seriously weird.
– fuz
8 hours ago
This is seriously weird.
– fuz
8 hours ago
2
2
I managed to reproduce this with just GCC (no CMake), so I edited the question to make the example more minimal.
– Joseph Sible
8 hours ago
I managed to reproduce this with just GCC (no CMake), so I edited the question to make the example more minimal.
– Joseph Sible
8 hours ago
Possibly related stackoverflow.com/questions/32730643/…
– Sami Kuhmonen
8 hours ago
Possibly related stackoverflow.com/questions/32730643/…
– Sami Kuhmonen
8 hours ago
You might be right, part of the he answer has to be around READ_IMPLIES_EXEC persona
– Benyamin Hirschberg
7 hours ago
You might be right, part of the he answer has to be around READ_IMPLIES_EXEC persona
– Benyamin Hirschberg
7 hours ago
add a comment
|
2 Answers
2
active
oldest
votes
Linux has an execution domain called READ_IMPLIES_EXEC
, which causes all pages allocated with PROT_READ
to also be given PROT_EXEC
. This program will show you whether that's enabled for itself:
#include <stdio.h>
#include <sys/personality.h>
int main(void) {
printf("Read-implies-exec is %sn", personality(0xffffffff) & READ_IMPLIES_EXEC ? "true" : "false");
return 0;
}
If you compile that along with an empty .s
file, you'll see that it's enabled, but without one, it'll be disabled. The initial value of this comes from the ELF meta-information in your binary. Do readelf -Wl example
. You'll see this line when you compiled without the empty .s
file:
GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x10
But this one when you compiled with it:
GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RWE 0x10
Note RWE
instead of just RW
. The reason for this is that the linker assumes that your assembly files require read-implies-exec unless it's explicitly told that they don't, and if any part of your program requires read-implies-exec, then it's enabled for your whole program. The assembly files that GCC compiles tell it that it doesn't need this, with this line (you'll see this if you compile with -S
):
.section .note.GNU-stack,"",@progbits
Put that line in example.s
, and it will serve to tell the linker that it doesn't need it either, and your program will then work as expected.
1
Holy crap, that's a weird default. I guess the toolchain existed before noexec, and making noexec the default could have broken things. Now I'm curious how other assemblers like NASM / YASM create.o
files! But anyway, I guess this is the mechanism thatgcc -zexecstack
uses, and why it makes not just the stack but everything executable.
– Peter Cordes
7 hours ago
add a comment
|
As an alternative to modifying your assembly files with GNU-specific section directive variants, you can add -Wa,--noexecstack
to your command line for building assembly files. For example, see how I do it in musl's configure
:
https://git.musl-libc.org/cgit/musl/commit/configure?id=adefe830dd376be386df5650a09c313c483adf1a
I believe at least some versions of clang with integrated-assembler may require it to be passed as --noexecstack
(without the -Wa
), so your configure script should probably check both and see which is accepted.
You can also use -Wl,-z,noexecstack
at link time (in LDFLAGS
) to get the same result. The disadvantage of this is that it doesn't help if your project is produces static (.a
) library files, since you then don't control the link-time options when it's used by other programs.
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f58260465%2fincorrect-mmap-behavior-when-assembly-files-in-included-in-the-project%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Linux has an execution domain called READ_IMPLIES_EXEC
, which causes all pages allocated with PROT_READ
to also be given PROT_EXEC
. This program will show you whether that's enabled for itself:
#include <stdio.h>
#include <sys/personality.h>
int main(void) {
printf("Read-implies-exec is %sn", personality(0xffffffff) & READ_IMPLIES_EXEC ? "true" : "false");
return 0;
}
If you compile that along with an empty .s
file, you'll see that it's enabled, but without one, it'll be disabled. The initial value of this comes from the ELF meta-information in your binary. Do readelf -Wl example
. You'll see this line when you compiled without the empty .s
file:
GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x10
But this one when you compiled with it:
GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RWE 0x10
Note RWE
instead of just RW
. The reason for this is that the linker assumes that your assembly files require read-implies-exec unless it's explicitly told that they don't, and if any part of your program requires read-implies-exec, then it's enabled for your whole program. The assembly files that GCC compiles tell it that it doesn't need this, with this line (you'll see this if you compile with -S
):
.section .note.GNU-stack,"",@progbits
Put that line in example.s
, and it will serve to tell the linker that it doesn't need it either, and your program will then work as expected.
1
Holy crap, that's a weird default. I guess the toolchain existed before noexec, and making noexec the default could have broken things. Now I'm curious how other assemblers like NASM / YASM create.o
files! But anyway, I guess this is the mechanism thatgcc -zexecstack
uses, and why it makes not just the stack but everything executable.
– Peter Cordes
7 hours ago
add a comment
|
Linux has an execution domain called READ_IMPLIES_EXEC
, which causes all pages allocated with PROT_READ
to also be given PROT_EXEC
. This program will show you whether that's enabled for itself:
#include <stdio.h>
#include <sys/personality.h>
int main(void) {
printf("Read-implies-exec is %sn", personality(0xffffffff) & READ_IMPLIES_EXEC ? "true" : "false");
return 0;
}
If you compile that along with an empty .s
file, you'll see that it's enabled, but without one, it'll be disabled. The initial value of this comes from the ELF meta-information in your binary. Do readelf -Wl example
. You'll see this line when you compiled without the empty .s
file:
GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x10
But this one when you compiled with it:
GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RWE 0x10
Note RWE
instead of just RW
. The reason for this is that the linker assumes that your assembly files require read-implies-exec unless it's explicitly told that they don't, and if any part of your program requires read-implies-exec, then it's enabled for your whole program. The assembly files that GCC compiles tell it that it doesn't need this, with this line (you'll see this if you compile with -S
):
.section .note.GNU-stack,"",@progbits
Put that line in example.s
, and it will serve to tell the linker that it doesn't need it either, and your program will then work as expected.
1
Holy crap, that's a weird default. I guess the toolchain existed before noexec, and making noexec the default could have broken things. Now I'm curious how other assemblers like NASM / YASM create.o
files! But anyway, I guess this is the mechanism thatgcc -zexecstack
uses, and why it makes not just the stack but everything executable.
– Peter Cordes
7 hours ago
add a comment
|
Linux has an execution domain called READ_IMPLIES_EXEC
, which causes all pages allocated with PROT_READ
to also be given PROT_EXEC
. This program will show you whether that's enabled for itself:
#include <stdio.h>
#include <sys/personality.h>
int main(void) {
printf("Read-implies-exec is %sn", personality(0xffffffff) & READ_IMPLIES_EXEC ? "true" : "false");
return 0;
}
If you compile that along with an empty .s
file, you'll see that it's enabled, but without one, it'll be disabled. The initial value of this comes from the ELF meta-information in your binary. Do readelf -Wl example
. You'll see this line when you compiled without the empty .s
file:
GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x10
But this one when you compiled with it:
GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RWE 0x10
Note RWE
instead of just RW
. The reason for this is that the linker assumes that your assembly files require read-implies-exec unless it's explicitly told that they don't, and if any part of your program requires read-implies-exec, then it's enabled for your whole program. The assembly files that GCC compiles tell it that it doesn't need this, with this line (you'll see this if you compile with -S
):
.section .note.GNU-stack,"",@progbits
Put that line in example.s
, and it will serve to tell the linker that it doesn't need it either, and your program will then work as expected.
Linux has an execution domain called READ_IMPLIES_EXEC
, which causes all pages allocated with PROT_READ
to also be given PROT_EXEC
. This program will show you whether that's enabled for itself:
#include <stdio.h>
#include <sys/personality.h>
int main(void) {
printf("Read-implies-exec is %sn", personality(0xffffffff) & READ_IMPLIES_EXEC ? "true" : "false");
return 0;
}
If you compile that along with an empty .s
file, you'll see that it's enabled, but without one, it'll be disabled. The initial value of this comes from the ELF meta-information in your binary. Do readelf -Wl example
. You'll see this line when you compiled without the empty .s
file:
GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x10
But this one when you compiled with it:
GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RWE 0x10
Note RWE
instead of just RW
. The reason for this is that the linker assumes that your assembly files require read-implies-exec unless it's explicitly told that they don't, and if any part of your program requires read-implies-exec, then it's enabled for your whole program. The assembly files that GCC compiles tell it that it doesn't need this, with this line (you'll see this if you compile with -S
):
.section .note.GNU-stack,"",@progbits
Put that line in example.s
, and it will serve to tell the linker that it doesn't need it either, and your program will then work as expected.
edited 7 hours ago
Martin Rosenau
10.4k2 gold badges10 silver badges22 bronze badges
10.4k2 gold badges10 silver badges22 bronze badges
answered 7 hours ago
Joseph SibleJoseph Sible
13.3k3 gold badges16 silver badges47 bronze badges
13.3k3 gold badges16 silver badges47 bronze badges
1
Holy crap, that's a weird default. I guess the toolchain existed before noexec, and making noexec the default could have broken things. Now I'm curious how other assemblers like NASM / YASM create.o
files! But anyway, I guess this is the mechanism thatgcc -zexecstack
uses, and why it makes not just the stack but everything executable.
– Peter Cordes
7 hours ago
add a comment
|
1
Holy crap, that's a weird default. I guess the toolchain existed before noexec, and making noexec the default could have broken things. Now I'm curious how other assemblers like NASM / YASM create.o
files! But anyway, I guess this is the mechanism thatgcc -zexecstack
uses, and why it makes not just the stack but everything executable.
– Peter Cordes
7 hours ago
1
1
Holy crap, that's a weird default. I guess the toolchain existed before noexec, and making noexec the default could have broken things. Now I'm curious how other assemblers like NASM / YASM create
.o
files! But anyway, I guess this is the mechanism that gcc -zexecstack
uses, and why it makes not just the stack but everything executable.– Peter Cordes
7 hours ago
Holy crap, that's a weird default. I guess the toolchain existed before noexec, and making noexec the default could have broken things. Now I'm curious how other assemblers like NASM / YASM create
.o
files! But anyway, I guess this is the mechanism that gcc -zexecstack
uses, and why it makes not just the stack but everything executable.– Peter Cordes
7 hours ago
add a comment
|
As an alternative to modifying your assembly files with GNU-specific section directive variants, you can add -Wa,--noexecstack
to your command line for building assembly files. For example, see how I do it in musl's configure
:
https://git.musl-libc.org/cgit/musl/commit/configure?id=adefe830dd376be386df5650a09c313c483adf1a
I believe at least some versions of clang with integrated-assembler may require it to be passed as --noexecstack
(without the -Wa
), so your configure script should probably check both and see which is accepted.
You can also use -Wl,-z,noexecstack
at link time (in LDFLAGS
) to get the same result. The disadvantage of this is that it doesn't help if your project is produces static (.a
) library files, since you then don't control the link-time options when it's used by other programs.
add a comment
|
As an alternative to modifying your assembly files with GNU-specific section directive variants, you can add -Wa,--noexecstack
to your command line for building assembly files. For example, see how I do it in musl's configure
:
https://git.musl-libc.org/cgit/musl/commit/configure?id=adefe830dd376be386df5650a09c313c483adf1a
I believe at least some versions of clang with integrated-assembler may require it to be passed as --noexecstack
(without the -Wa
), so your configure script should probably check both and see which is accepted.
You can also use -Wl,-z,noexecstack
at link time (in LDFLAGS
) to get the same result. The disadvantage of this is that it doesn't help if your project is produces static (.a
) library files, since you then don't control the link-time options when it's used by other programs.
add a comment
|
As an alternative to modifying your assembly files with GNU-specific section directive variants, you can add -Wa,--noexecstack
to your command line for building assembly files. For example, see how I do it in musl's configure
:
https://git.musl-libc.org/cgit/musl/commit/configure?id=adefe830dd376be386df5650a09c313c483adf1a
I believe at least some versions of clang with integrated-assembler may require it to be passed as --noexecstack
(without the -Wa
), so your configure script should probably check both and see which is accepted.
You can also use -Wl,-z,noexecstack
at link time (in LDFLAGS
) to get the same result. The disadvantage of this is that it doesn't help if your project is produces static (.a
) library files, since you then don't control the link-time options when it's used by other programs.
As an alternative to modifying your assembly files with GNU-specific section directive variants, you can add -Wa,--noexecstack
to your command line for building assembly files. For example, see how I do it in musl's configure
:
https://git.musl-libc.org/cgit/musl/commit/configure?id=adefe830dd376be386df5650a09c313c483adf1a
I believe at least some versions of clang with integrated-assembler may require it to be passed as --noexecstack
(without the -Wa
), so your configure script should probably check both and see which is accepted.
You can also use -Wl,-z,noexecstack
at link time (in LDFLAGS
) to get the same result. The disadvantage of this is that it doesn't help if your project is produces static (.a
) library files, since you then don't control the link-time options when it's used by other programs.
answered 3 hours ago
R..R..
165k29 gold badges278 silver badges596 bronze badges
165k29 gold badges278 silver badges596 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f58260465%2fincorrect-mmap-behavior-when-assembly-files-in-included-in-the-project%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
This is seriously weird.
– fuz
8 hours ago
2
I managed to reproduce this with just GCC (no CMake), so I edited the question to make the example more minimal.
– Joseph Sible
8 hours ago
Possibly related stackoverflow.com/questions/32730643/…
– Sami Kuhmonen
8 hours ago
You might be right, part of the he answer has to be around READ_IMPLIES_EXEC persona
– Benyamin Hirschberg
7 hours ago