2

I am attempting to compile a simulator for Y86-64 code on Linux.I have already rewritten the makefile but it turned out like below.It said "undefined reference for 'matherr'".(Looks like it connects with gcc when linking)

(cd pipe; make all GUIMODE=-DHAS_GUI TKLIBS="-L/usr/lib/ -ltk8.5 -ltcl8.5" TKINC="-I/usr/include/tcl8.5 ")
    make[1]: 进入目录“/home/gongchen/桌面/ICS/archlab-handout/sim/pipe”
    # Building the pipe-std.hcl version of PIPE
    ../misc/hcl2c -n pipe-std.hcl < pipe-std.hcl > pipe-std.c
    gcc -Wall -O2 -I/usr/include/tcl8.5  -I../misc -DHAS_GUI -o psim psim.c pipe-std.c \
        ../misc/isa.c -L/usr/lib/ -ltk8.5 -ltcl8.5 -lm
    /tmp/cchKTZy7.o:(.data.rel+0x0):对‘matherr’未定义的引用
    collect2: error: ld returned 1 exit status
    Makefile:42: recipe for target 'psim' failed
    make[1]: *** [psim] Error 1
    make[1]: 离开目录“/home/gongchen/桌面/ICS/archlab-handout/sim/pipe”
    Makefile:28: recipe for target 'all' failed
    make: *** [all] Error 2
jww
  • 97,681
  • 90
  • 411
  • 885
gcc17
  • 91
  • 1
  • 9
  • 2
    Duplicate of https://stackoverflow.com/questions/52417962/undefined-reference-to-matherr-when-building-y86-from-sources – tripleee Oct 20 '18 at 08:03
  • @My_Lulu - I think Tripleee found the root cause. It is an antique project from 2002, and it is probably abandoned. It looks like there are several forks of Y86 project. Maybe you can try another fork. The fork at [hczhcz | y86](https://github.com/hczhcz/y86) on GitHub does not appear to reference the `matherr` symbol. – jww Oct 20 '18 at 09:08
  • `libm.so` doesn't have these symbols anymore, just comment out code related with matherr – Ju Piece Jun 26 '19 at 05:50

2 Answers2

5
gcc -Wall -O2 -I/usr/include/tcl8.5  -I../misc -DHAS_GUI -o psim psim.c pipe-std.c \
    ../misc/isa.c -L/usr/lib/ -ltk8.5 -ltcl8.5 -lm
/tmp/cchKTZy7.o:(.data.rel+0x0):对‘matherr’未定义的引用

You are linking and getting an undefined reference error to matherr.

It looks like matherr is part of SVID math library. According to the matherr(3) man page the symbol is no longer present in Glibc 2.27 or above.

DESCRIPTION

Note: the mechanism described in this page is no longer supported by glibc. Before glibc 2.27, it had been marked as obsolete. Since glibc 2.27, the mechanism has been removed altogether. New applications should use the techniques described in math_error(7) and fenv(3). This page documents the matherr() mechanism as an aid for maintaining and porting older applications.

The math_error(7) man page says that you should do the following to check for errors:

  1. set errno to zero
  2. call feclearexcept(FE_ALL_EXCEPT);

After the math calculation completes you should check the following for non-zero value to indicate error:

  1. errno
  2. fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW);

Since you are a guy or gal trying to use the program (and not a maintainer) I suggest two courses of actions. The strategy is to use a distro where things just work, and punt to the Y86 maintainer to fix it.

First, use a different, older distro that provides Glibc 2.26 or early. Something like Debian 8 (Glibc 2.19) or Fedora 25 (Glibc 2.24) should do just fine.

Second, file a bug report against Y86 project. The Y86 maintainers need to fix the problem, not students trying to learn the class material.

jww
  • 97,681
  • 90
  • 411
  • 885
5

My classmates have a way to solve this problem: comment the code related to matherr, like the code in the picture. And the GUI mode works. 好厉害! enter image description here

Akshay Paliwal
  • 3,718
  • 2
  • 39
  • 43