diff mbox

[google,4.6] Bug fix to function reordering plugin to check presence of elf.h

Message ID CAAs8HmzQBim4ea3fQ5TvXwTwcnQokLKLUo2yf8FR3xHqAD3fDw@mail.gmail.com
State New
Headers show

Commit Message

Sriraman Tallam Feb. 25, 2012, 12:19 a.m. UTC
function_reordering_plugin.c includes <elf.h> which is not available
on non-ELF platforms building a cross-compiler. This patch checks for
<elf.h> before including it. Otherwise, it redefines the macros used.
This is safe because the macros will not change.

For context, this linker plugin itself is only available in the google
4_6 branch and I will port it to other branches and make it available
for review for trunk soon.


2012-02-24  Sriraman Tallam  <tmsriram@google.com>

	* function_reordering_plugin.c: Check for presence of elf.h.
	Otherwise, redefine the elf macros used.

Ok to commit?

Thanks,
-Sri.

Comments

Xinliang David Li Feb. 25, 2012, 7:18 a.m. UTC | #1
ok.

David

On Fri, Feb 24, 2012 at 4:19 PM, Sriraman Tallam <tmsriram@google.com> wrote:
> function_reordering_plugin.c includes <elf.h> which is not available
> on non-ELF platforms building a cross-compiler. This patch checks for
> <elf.h> before including it. Otherwise, it redefines the macros used.
> This is safe because the macros will not change.
>
> For context, this linker plugin itself is only available in the google
> 4_6 branch and I will port it to other branches and make it available
> for review for trunk soon.
>
>
> 2012-02-24  Sriraman Tallam  <tmsriram@google.com>
>
>        * function_reordering_plugin.c: Check for presence of elf.h.
>        Otherwise, redefine the elf macros used.
>
> Ok to commit?
>
> Thanks,
> -Sri.
Sriraman Tallam Feb. 25, 2012, 9:40 p.m. UTC | #2
Committed now, thanks.

-Sri.

On Fri, Feb 24, 2012 at 11:18 PM, Xinliang David Li <davidxl@google.com> wrote:
> ok.
>
> David
>
> On Fri, Feb 24, 2012 at 4:19 PM, Sriraman Tallam <tmsriram@google.com> wrote:
>> function_reordering_plugin.c includes <elf.h> which is not available
>> on non-ELF platforms building a cross-compiler. This patch checks for
>> <elf.h> before including it. Otherwise, it redefines the macros used.
>> This is safe becaue the macros will not change.
>>
>> For context, this linker plugin itself is only available in the google
>> 4_6 branch and I will port it to other branches and make it available
>> for review for trunk soon.
>>
>>
>> 2012-02-24  Sriraman Tallam  <tmsriram@google.com>
>>
>>        * function_reordering_plugin.c: Check for presence of elf.h.
>>        Otherwise, redefine the elf macros used.
>>
>> Ok to commit?
>>
>> Thanks,
>> -Sri.
Jing Yu March 1, 2012, 9:31 p.m. UTC | #3
I ported this patch into google/gcc-4_6_2-mobile.
Thanks,
Jing

On Sat, Feb 25, 2012 at 1:40 PM, Sriraman Tallam <tmsriram@google.com> wrote:
> Committed now, thanks.
>
> -Sri.
>
> On Fri, Feb 24, 2012 at 11:18 PM, Xinliang David Li <davidxl@google.com> wrote:
>> ok.
>>
>> David
>>
>> On Fri, Feb 24, 2012 at 4:19 PM, Sriraman Tallam <tmsriram@google.com> wrote:
>>> function_reordering_plugin.c includes <elf.h> which is not available
>>> on non-ELF platforms building a cross-compiler. This patch checks for
>>> <elf.h> before including it. Otherwise, it redefines the macros used.
>>> This is safe becaue the macros will not change.
>>>
>>> For context, this linker plugin itself is only available in the google
>>> 4_6 branch and I will port it to other branches and make it available
>>> for review for trunk soon.
>>>
>>>
>>> 2012-02-24  Sriraman Tallam  <tmsriram@google.com>
>>>
>>>        * function_reordering_plugin.c: Check for presence of elf.h.
>>>        Otherwise, redefine the elf macros used.
>>>
>>> Ok to commit?
>>>
>>> Thanks,
>>> -Sri.
diff mbox

Patch

Index: function_reordering_plugin/function_reordering_plugin.c
===================================================================
--- function_reordering_plugin/function_reordering_plugin.c	(revision 184564)
+++ function_reordering_plugin/function_reordering_plugin.c	(working copy)
@@ -43,11 +43,23 @@  along with this program; see the file COPYING3.  I
 #include <stdlib.h>
 #include <assert.h>
 #include <string.h>
-#include <elf.h>
+#if  defined (__ELF__)
+  #include <elf.h>
+#endif
 #include "config.h"
 #include "plugin-api.h"
 #include "callgraph.h"
 
+/* #include <elf.h>   Not available on Darwin. 
+   Rather than dealing with cross-compilation includes, hard code the
+   values we need, as these will not change.  */
+#ifndef SHT_NULL
+ #define SHT_NULL 0
+#endif
+#ifndef SHT_PROGBITS
+ #define SHT_PROGBITS 1
+#endif
+
 enum ld_plugin_status claim_file_hook (const struct ld_plugin_input_file *file,
                                        int *claimed);
 enum ld_plugin_status all_symbols_read_hook ();