[FFmpeg-devel] Mark .rodata section as read only in COFF object file

Submitted by Tom Tan on Jan. 15, 2019, 1:23 a.m.

Details

Message ID MWHPR21MB0750D3F9CDCB494552C6844FE2810@MWHPR21MB0750.namprd21.prod.outlook.com
State Accepted
Commit 41cf3e3b1ca375962951fde1b90a03b16197d205
Headers show

Commit Message

Tom Tan Jan. 15, 2019, 1:23 a.m.
Hi Carl Eugen,

Could you please review the updated patch? Thanks.

From 9f20fb097b8006ad38634a943298e47884bf2696 Mon Sep 17 00:00:00 2001
From: Tom Tan <Tom.Tan@microsoft.com>

Date: Thu, 10 Jan 2019 11:50:49 -0800
Subject: [PATCH] Switch .rodata section name to .rdata for COFF object file

.rodata section is custom section name for COFF object file, so it would not be
set as read-only by assembler as default. Switch to name .rdata which is
wellknown in compilers/assemblers targeting COFF, and .rdata is read-only by
default.

This is common for COFF on all architectures.
---
 libavutil/aarch64/asm.S | 2 ++
 libavutil/arm/asm.S     | 2 ++
 2 files changed, 4 insertions(+)

-- 
2.15.1.gvfs.2.39.g03d366a


-----Original Message-----
From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Tom Tan

Sent: Friday, January 11, 2019 11:38 AM
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Cc: Martin Storsjö <martin@martin.st>
Subject: Re: [FFmpeg-devel] [PATCH] Mark .rodata section as read only in COFF object file

Thanks Carl. Martin made a better fix when porting this to libav which uses .rdata as section name instead of .rodata with explicit read-only property. .rdata is read-only in COFF by default. I updated my patch accordingly, thanks Martin.

Yes, this applies to 32-bit arm for Windows, the new patch includes this update. This also affects Windows x86/x64, but this has already been handled as below macro from FFmpeg\libavutil\x86\x86inc.asm.

%macro SECTION_RODATA 0-1 16
    %ifidn __OUTPUT_FORMAT__,aout
        SECTION .text
    %elifidn __OUTPUT_FORMAT__,coff
        SECTION .text
    %elifidn __OUTPUT_FORMAT__,win32
        SECTION .rdata align=%1
    %elif WIN64
        SECTION .rdata align=%1
    %else
        SECTION .rodata align=%1
    %endif
%endmacro

-----Original Message-----
From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Carl Eugen Hoyos

Sent: Friday, January 11, 2019 5:07 AM
To: FFmpeg development discussions and patches <ffmpeg-devel@ffmpeg.org>
Subject: Re: [FFmpeg-devel] [PATCH] Mark .rodata section as read only in COFF object file

2019-01-10 21:14 GMT+01:00, Tom Tan <Tom.Tan@microsoft.com>:
> .rodata directive from GAS assembly produces .rodata as read/write for 

> COFF object file by default (object file format for Windows), but read 

> only for ELF. This change marks it as read only explicitly for COFF.

>

> The issue happens when building Chromium for Windows ARM64, with FFmpeg.


Does this issue only apply to arm64 or also 32bit arm?

Carl Eugen
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://nam06.safelinks.protection.outlook.com/?url=http%3A%2F%2Fffmpeg.org%2Fmailman%2Flistinfo%2Fffmpeg-devel&amp;data=02%7C01%7CTom.Tan%40microsoft.com%7C772878d0ce9d4aba928d08d677fc59fd%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636828323131911457&amp;sdata=jcwHGJFiTaIo7fUZ8OGEOoOhrm43d0uN0HlmbmozKPA%3D&amp;reserved=0

Patch hide | download patch | download mbox

diff --git a/libavutil/aarch64/asm.S b/libavutil/aarch64/asm.S
index fd32bf784e..5c329430fd 100644
--- a/libavutil/aarch64/asm.S
+++ b/libavutil/aarch64/asm.S
@@ -63,6 +63,8 @@  ELF     .size   \name, . - \name
 .else
         .section        .rodata
 .endif
+#elif defined(_WIN32)
+        .section        .rdata
 #elif !defined(__MACH__)
         .section        .rodata
 #else
diff --git a/libavutil/arm/asm.S b/libavutil/arm/asm.S
index 6744f2a200..59298d90eb 100644
--- a/libavutil/arm/asm.S
+++ b/libavutil/arm/asm.S
@@ -117,6 +117,8 @@  ELF     .size   \name, . - \name
 .else
         .section        .rodata
 .endif
+#elif defined(_WIN32)
+        .section        .rdata
 #elif !defined(__MACH__)
         .section        .rodata
 #else