bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug gold/21066] icf folds template functions with different exception h


From: oremanj at gmail dot com
Subject: [Bug gold/21066] icf folds template functions with different exception handling semantics
Date: Fri, 10 Aug 2018 16:19:18 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=21066

--- Comment #4 from Joshua Oreman <oremanj at gmail dot com> ---
As I pointed out in PR 23482, hot/cold function splitting (the new gcc
-freorder-blocks-and-partition optimization) can make this an issue even
without any LSDA at all. Seems a full fix will need to consider the CIE/FDE
contents that are relevant to the function as well.

Example uses asm for clarity, but I can obtain analogous issues using
gcc-produced code, as demonstrated on the above PR.

$ g++ -o t.nofold t.cc -fuse-ld=gold
$ g++ -o t.fold t.cc -fuse-ld=gold -Wl,--icf=safe
$ ./t.nofold
caught 1: 42
caught 2: 42
$ ./t.fold
caught 1: 42
terminate called after throwing an instance of 'int'
Aborted (core dumped)
$ cat t.cc

extern "C" int printf(const char *fmt, ...);

void throw_it() { throw 42; }
extern void call_1(void(*)());
extern void call_2(void(*)());

asm(R"(
        .section .text._Z6call_1PFvvE,"ax",@progbits
        .globl _Z6call_1PFvvE
        .type _Z6call_1PFvvE, @function
_Z6call_1PFvvE:
        .cfi_startproc
        pushq   %rbx
        .cfi_def_cfa_offset 16
        .cfi_offset 3, -16
        jmp     _Z6call_1PFvvE.cold
        .cfi_endproc

        .section .text.unlikely._Z6call_1PFvvE,"ax",@progbits
        .type _Z6call_1PFvvE.cold, @function
_Z6call_1PFvvE.cold:
        .cfi_startproc
        .cfi_def_cfa_offset 16
        .cfi_offset 3, -16
        call    *%rdi
        .cfi_endproc

        .section .text._Z6call_2PFvvE,"ax",@progbits
        .globl _Z6call_2PFvvE
        .type _Z6call_2PFvvE, @function
_Z6call_2PFvvE:
        .cfi_startproc
        subq    $24, %rsp
        .cfi_def_cfa_offset 32
        jmp     _Z6call_2PFvvE.cold
        .cfi_endproc

        .section .text.unlikely._Z6call_2PFvvE,"ax",@progbits
        .type _Z6call_2PFvvE.cold, @function
_Z6call_2PFvvE.cold:
        .cfi_startproc
        .cfi_def_cfa_offset 32
        call    *%rdi
        .cfi_endproc
)");

int main() {
    try {
        call_1(throw_it);
    } catch (int val) {
        printf("caught 1: %d\n", val);
    }
    try {
        call_2(throw_it);
    } catch (int val) {
        printf("caught 2: %d\n", val);
    }
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]