Home Dashboard Directory Help

C++ #pragma secion doesn't allow read,write,execute by Johan O Levin


 as Fixed Help for as Fixed

Sign in
to vote
Type: Bug
ID: 633782
Opened: 12/29/2010 7:59:54 AM
Access Restriction: Public
User(s) can reproduce this bug


Compiling a C++ file with this declaration:

#pragma section("gencode", read, write, execute)

results in a section that is read/execute, but not writable.

Running dumpbin /headers gives this(partial) result:
gencode name
    BC80 virtual size
20000 virtual address (10020000 to 1002BC7F)
    BE00 size of raw data
    D200 file pointer to raw data (0000D200 to 00018FFF)
     0 file pointer to relocation table
     0 file pointer to line numbers
     0 number of relocations
     0 number of line numbers
60000040 flags
         Initialized Data
         Execute Read

Other combinations or read, write and execute generate correct output, but read, write and execute together result in a section without write access.

Is this by design or a bug? I can't find the behavior described anywhere.
Sign in to post a comment.
Posted by Microsoft on 2/7/2011 at 10:20 AM
Hi Johan:
    Thanks for reporting the issue.
    A fix for the missing warning has been checked into the compiler sources. The fix should show up in the next release of Visual C++.

Xiang Fan
Visual C++ Team
Posted by Johan O Levin on 1/13/2011 at 12:17 AM
Thank you.

It would have been a lot easier to debug if the linker had given a warning or an error message instead of just ignoring the directive, though.
Posted by Microsoft on 1/12/2011 at 4:27 PM
Hi Johan:
    It is by-design. The compiler will ignore the write attribute on code section.
    You can take a look at the following blog post for the portable and safe way to run dynamically generate code.


Xiang Fan
Visual C++ Team
Posted by Microsoft on 12/29/2010 at 8:16 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.