patchgperf - Patches: patch #7383, Fix error when generated C code is...


You are not allowed to post comments on this tracker with your current authentication level.

patch #7383: Fix error when generated C code is compiled as C++

Submitted by:  Erik Johansson <erijo>
Submitted on:  Fri 12 Nov 2010 10:38:03 AM UTC  
Category: NonePriority: 5 - Normal
Status: DonePrivacy: Public
Assigned to: Bruno Haible <haible>Open/Closed: Closed

Sun 27 Nov 2016 05:29:26 PM UTC, comment #1:

Thanks. Your patch looks good.

However, I happened to fix by reducing complexity (giving up on inlining the lookup function entirely) rather than by adding even more #ifs to this fragile area. It fixes your "How to reproduce the problem" steps.

Bruno Haible <haible>
Project AdministratorIn charge of this item.
Fri 12 Nov 2010 10:38:03 AM UTC, original submission:

If a generated hash file in C is included in a C++ file which is compiled with inlining disabled (e.g. -O0) the process will fail in the link stage due to missing symbols.

The reason for this is that the attribute _gnu_inline_ has a different meaning for C and C++. For C code it means "inline where possible and create a standalone function". For C++ code it means "inline where possible, but don't create a standalone function". If inlining is disabled the C++ compiler will not generate any code causing the build to fail in the link stage.

Fix this by not adding the attribute if the code is compiled as C++ code with inlining disabled.

This has been discussed on bug-gperf:

How to reproduce the problem:
1. cd test
2. make check-c
3. echo -e '#include "cinset.c"\nint main() { in_word_set("for", 3); }' > main.cpp
4a. g++ -o main main.cpp

/tmp/ccplX60t.o: In function `main':
main.cpp:(.text+0x19): undefined reference to `in_word_set(char const*, unsigned int)'
collect2: ld returned 1 exit status

4b. g++ -O1 -o main main.cpp
=> works

5. Apply patch
6. make -C ..
7. make check-c
8a. g++ -o main main.cpp
=> works
8b. g++ -O1 -o main main.cpp
=> works

Erik Johansson <erijo>



Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -unavailable- added by haible (Posted a comment)
  • -unavailable- added by erijo (Submitted the item)

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.


    Please enter the title of George Orwell's famous dystopian book (it's a date):



    Follow 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sun 27 Nov 2016 05:29:26 PM UTChaibleStatusNone=>Done
      Assigned toNone=>haible
    Fri 12 Nov 2010 10:38:03 AM UTCerijoAttached File-=>Added Fix-error-when-generated-C-code-is-compiled-as-C.patch, #21990

    Back to the top

    Powered by Savane 3.1-cleanup1