This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [GOLD] Support --icf=safe with -pie for x86_64


On Thu, Jan 12, 2017 at 01:28:49PM -0800, Rahul Chaudhry via binutils wrote:
> +    case elfcpp::R_X86_64_PC32:
> +      {
> +        // This relocation may be used both for function calls and
> +        // for taking address of a function. We distinguish between
> +        // them by checking the opcodes.
> +        section_size_type stype;
> +        const unsigned char* view = src_obj->section_contents(src_indx,
> +                                                              &stype,
> +                                                              true);
> +
> +        // call
> +        if (r_offset >= 1
> +            && view[r_offset - 1] == 0xe8)
> +          return false;

Is it safe to assume that 0xe8 is really the start of an instruction?

What if instead you are looking at a modrm or sib for a rip-relative read?
It may not match in this case (I'm rusty at x86 and would have to look
at an AMD or Intel manual to know) but your should check this and of
course for the other encodings below.

Also, might you have an R_X86_64_PC32 in data and so be looking at the
high byte of the previous word?

> +
> +        // jmp
> +        if (r_offset >= 1
> +            && view[r_offset - 1] == 0xe9)
> +          return false;
> +
> +        // jo/jno/jb/jnb/je/jne/jna/ja/js/jns/jp/jnp/jl/jge/jle/jg
> +        if (r_offset >= 2
> +            && view[r_offset - 2] == 0x0f
> +            && view[r_offset - 1] >= 0x80
> +            && view[r_offset - 1] <= 0x8f)
> +          return false;
> +
> +        // Be conservative and treat all others as function pointers.
> +        return true;
> +      }
>      }
>    return false;
>  }

-- 
Alan Modra
Australia Development Lab, IBM


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]