Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution for "'multiple definition of yylloc' error #4

Open
c-shankar opened this issue Jul 22, 2020 · 16 comments
Open

Solution for "'multiple definition of yylloc' error #4

c-shankar opened this issue Jul 22, 2020 · 16 comments

Comments

@c-shankar
Copy link

c-shankar commented Jul 22, 2020

If you are facing the following error,

usr/bin/ld: scripts/dtc/dtc-parser.tab.o:(.bss+0x10): multiple definition of 'yylloc'; scripts/dtc/dtc-lexer.lex.o:(.bss+0x0): first defined here

collect2: error: ld returned 1 exit status

edit the file ./linux-rtk/scripts/dtc/dtc-lexer-lex.c
Find the line 'YYLTYPE yylloc' and change it to 'extern YYLTYPE yylloc'

reference : https://lkml.org/lkml/2020/4/1/1206

@rhakh
Copy link

rhakh commented Nov 29, 2021

The possible reason is wrong version of GCC. Please try gcc-9 or older.
Previously, I used gcc-10, and got this issue. Then installed gcc-9, and everything were successfully build.

@paralin
Copy link

paralin commented Dec 29, 2021

git am https://github.com/Tomoms/android_kernel_oppo_msm8974/commit/11647f99b4de6bc460e106e876f72fc7af3e54a6.patch

bwalle added a commit to bwalle/ptxdist-vetero that referenced this issue Jan 29, 2022
@Aheadboy
Copy link

The possible reason is wrong version of GCC. Please try gcc-9 or older. Previously, I used gcc-10, and got this issue. Then installed gcc-9, and everything were successfully build.

maybee, my gcc version is : gcc version 11.2.0 (Ubuntu 11.2.0-7ubuntu2)

@Aheadboy
Copy link

Aheadboy commented May 28, 2022

dtc-lexer-lex.c

I met this issue when I build android7 in ubuntu22. But why am I not found dtc-lexer-lex.c in aosp path

@Pranav-flo
Copy link

This issue occurs during kernel compilation. I resolved it by adding extern to yylloc.
You can find the file in (root directory of kernel folder)/scripts/dtc/dtc-lexer-lex.c
Also if dtc-lexer.lex.c_shipped file exists in the path make sure to extern yylloc here as well.

image
image

@hamzajrifi
Copy link

that's same happen with me when update gcc-9 to gcc-11
and i fixed it when i receive my last version gcc-9 and that's work whit me
i used this command
==> sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 9

@ShawnYang23
Copy link

If you are facing the following error,

usr/bin/ld: scripts/dtc/dtc-parser.tab.o:(.bss+0x10): multiple definition of 'yylloc'; scripts/dtc/dtc-lexer.lex.o:(.bss+0x0): first defined here

collect2: error: ld returned 1 exit status

edit the file ./linux-rtk/scripts/dtc/dtc-lexer-lex.c Find the line 'YYLTYPE yylloc' and change it to 'extern YYLTYPE yylloc'

reference : https://lkml.org/lkml/2020/4/1/1206

In some RK SDK, this symbol is placed in the file dtc-lexer.l

@MadhbhavikaR
Copy link

I was able to resolve the issue by applying the below patch (the file name was different in my case)

$ git diff
diff --git a/scripts/dtc/dtc-lexer.lex.c_shipped b/scripts/dtc/dtc-lexer.lex.c_shipped
index 2d30f41778b..d0eb405cb81 100644
--- a/scripts/dtc/dtc-lexer.lex.c_shipped
+++ b/scripts/dtc/dtc-lexer.lex.c_shipped
@@ -637,7 +637,7 @@ char *yytext;
 #include "srcpos.h"
 #include "dtc-parser.tab.h"
 
-YYLTYPE yylloc;
+extern YYLTYPE yylloc;
 
 /* CAUTION: this will stop working if we ever use yyless() or yyunput() */
 #define        YY_USER_ACTION \

@wbob
Copy link

wbob commented Nov 20, 2022

was stuck on this for too long - ignored the _shipped files at first. For context: those are being used in kernels prior to 4.17, see torvalds/linux@e039139be8c2 and https://lkml.org/lkml/2020/3/31/658

you need the patch in kernels < 5.6

@mcstarkteam
Copy link

不要找了国内的伙伴,使用gcc-9 完美解决
我是乐于助人的ATRI mua~

ElectricRCAircraftGuy referenced this issue in Tomoms/android_kernel_oppo_msm8974 Jan 9, 2023
commit e33a814e772cdc36436c8c188d8c42d019fda639 upstream.

gcc 10 will default to -fno-common, which causes this error at link
time:

  (.text+0x0): multiple definition of `yylloc'; dtc-lexer.lex.o (symbol from plugin):(.text+0x0): first defined here

This is because both dtc-lexer as well as dtc-parser define the same
global symbol yyloc. Before with -fcommon those were merged into one
defintion. The proper solution would be to to mark this as "extern",
however that leads to:

  dtc-lexer.l:26:16: error: redundant redeclaration of 'yylloc' [-Werror=redundant-decls]
   26 | extern YYLTYPE yylloc;
      |                ^~~~~~
In file included from dtc-lexer.l:24:
dtc-parser.tab.h:127:16: note: previous declaration of 'yylloc' was here
  127 | extern YYLTYPE yylloc;
      |                ^~~~~~
cc1: all warnings being treated as errors

which means the declaration is completely redundant and can just be
dropped.

Signed-off-by: Dirk Mueller <[email protected]>
Signed-off-by: David Gibson <[email protected]>
[robh: cherry-pick from upstream]
Cc: [email protected]
Signed-off-by: Rob Herring <[email protected]>
[nc: Also apply to dtc-lexer.lex.c_shipped due to a lack of
     e039139be8c2, where dtc-lexer.l started being used]
Signed-off-by: Nathan Chancellor <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
Change-Id: I7f299451e99aab09375883546e47505ec0937c26
@H3d9
Copy link

H3d9 commented Apr 22, 2023

This issue occurs during kernel compilation. I resolved it by adding extern to yylloc. You can find the file in (root directory of kernel folder)/scripts/dtc/dtc-lexer-lex.c Also if dtc-lexer.lex.c_shipped file exists in the path make sure to extern yylloc here as well.

image image

补充一下,不用重装gcc,找到这个文件,查找"YYLTYPE yylloc;"这一行,替换成"extern YYLTYPE yylloc;"即可。

@rhmcruiser
Copy link

rhmcruiser commented Jul 9, 2023

Kernel build successful after modifying dtc-lexer-lex.c in < kernel src directory>/scripts/dtc/
YYLYTYPE yylloc ==> extern YYLTYPE yylloc

( jfyi - I encountered this issue while building a custom linux arm kernel for qemu.

  • kernel tar source - linux-4.4.157 ( issue is specific to src file dtc-lexer-lex.c, and is fixed in version v4.17-rc1 and above)
  • gcc version - 11.3.0 on the host system running kernel 5.19-0.46
    )

@itsmahfoudi
Copy link

Hello,
I'm facing the same problem even if i have made changes to the scripts/dtc/dtc-lexer.lex.c, by replacing YYLTYPE yylloc with extern YYLTYPE yylloc,
This is what i'm getting :
/usr/bin/ld: scripts/dtc/dtc-parser.tab.o:(.bss+0x20): multiple definition of `yylloc'; scripts/dtc/dtc-lexer.lex.o:(.bss+0x0): first defined here collect2: error: ld returned 1 exit status
make[1]: *** [scripts/Makefile.host:101: scripts/dtc/dtc] Error 1
make: *** [Makefile:1244: scripts_dtc] Error 2

  • [[ 2 -ne 0 ]]
  • git apply /home/itsmeayoub/Documents/AYOUB/System_programming/assignment-1-FASKA2003/finder-app/dtc-multiple-definition.patch
    error: can't open patch '/home/itsmeayoub/Documents/AYOUB/System_programming/assignment-1-FASKA2003/finder-app/dtc-multiple-definition.patch': No such file or directory
  • set -e
    ++ nproc
  • make -j8 ARCH=arm64 CROSS_COMPILE=aarch64-none-linux-gnu- all
    HOSTLD scripts/dtc/dtc
    /usr/bin/ld: scripts/dtc/dtc-parser.tab.o:(.bss+0x20): multiple definition of `yylloc'; scripts/dtc/dtc-lexer.lex.o:(.bss+0x0): first defined here collect2: error: ld returned 1 exit status
    make[1]: *** [scripts/Makefile.host:101: scripts/dtc/dtc] Error 1
    make: *** [Makefile:1244: scripts_dtc] Error 2
    make: *** Waiting for unfinished jobs....

@H3d9
Copy link

H3d9 commented Sep 19, 2023

您可能没有清理旧的obj文件,请先删除“dtc-lexer.lex.o”然后构建,或者先全部清理(一般为make clean之类的命令)再重新构建。
Perhaps you didnot clean old obj file, please delete “dtc-lexer.lex.o” and build again, or clean all(some sort of command like "make clean") and rebuild again.

Dobby233Liu added a commit to lwys-trash-oct23/android_kernel_samsung_msm8916 that referenced this issue Oct 3, 2023
As suggested in:
BPI-SINOVOIP/BPI-M4-bsp#4#issuecomment-1140414552

Change-Id: I05cb1f34ddb73592d8822f4fbdf05579ad8a46bc
neubdd pushed a commit to intronik/linux that referenced this issue Dec 11, 2023
fix for
usr/bin/ld: scripts/dtc/dtc-parser.tab.o:(.bss+0x10): multiple definition of 'yylloc'; scripts/dtc/dtc-lexer.lex.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status

see BPI-SINOVOIP/BPI-M4-bsp#4 (comment)

edit the file ./linux-rtk/scripts/dtc/dtc-lexer-lex.c_shipped
Find the line 'YYLTYPE yylloc' and change it to 'extern YYLTYPE yylloc'
@G-lacier
Copy link

If you are facing the following error,

usr/bin/ld: scripts/dtc/dtc-parser.tab.o:(.bss+0x10): multiple definition of 'yylloc'; scripts/dtc/dtc-lexer.lex.o:(.bss+0x0): first defined here

collect2: error: ld returned 1 exit status

edit the file ./linux-rtk/scripts/dtc/dtc-lexer-lex.c Find the line 'YYLTYPE yylloc' and change it to 'extern YYLTYPE yylloc'

reference : https://lkml.org/lkml/2020/4/1/1206

This worked for me. I was trying to compile an android 4 kernel and kept getting this error.

@Yuyaowen
Copy link

不要找了国内的伙伴,使用gcc-9 完美解决 我是乐于助人的ATRI mua~

gcc9.5表示没解决

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests