Search

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

Closed
as Fixed Help for as Fixed

1
0
Sign in
to vote
Type: Bug
ID: 633782
Opened: 12/29/2010 7:59:54 AM
Access Restriction: Public
0
Workaround(s)
0
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:
SECTION HEADER #6
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.
Details (expand)

Visual Studio/Silverlight/Tooling version

Visual Studio 2010

What category (if any) best represents this feedback?

Compatibility

Steps to reproduce

1. Create a new C++ console application with this code:
#pragma section("gencode", read, write, execute)
static __declspec(allocate("gencode")) char scratch[2000];

int _tmain(int argc, _TCHAR* argv[])
{
    scratch[0] = 0;
    return 0;
}

2. Build and run.

Product Language

English

Operating System

Windows Vista

Operating System Language

English

Actual results

EXCEPTION_ACCESS_VIOLATION

Expected results

I expect to be able to write to the section. Running
dumpbin /headers filename.exe
I exptec my section to show up as read,write,execute and not read,execute.
File Attachments
0 attachments
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.

http://blogs.msdn.com/b/vcblog/archive/2009/05/21/dynamicbase-and-nxcompat.aspx

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.