# pkg install failure - Compilation failed unexpectedly



## joint (Oct 6, 2014)

Hi BSD-Colleagues,

There is an issue I'm facing with:
- When I tried to migrate the jail to PKGNG by installing PKG from ports
ports-mgmt/pkg  by using command:

`# cd /usr/ports/ports-mgmt/pkg && make UPGRADEPKG=1 install clean`

I ran into the errors issue like:

```
===>  License BSD2CLAUSE accepted by the user
=> pkg-1.3.8.tar.xz doesn't seem to exist in /usr/ports/distfiles/.
=> Attempting to fetch http://distcache.FreeBSD.org/local-distfiles/portmgr/pkg-1.3.8.tar.xz
pkg-1.3.8.tar.xz                              100% of 1744 kB 3459 kBps
===> Fetching all distfiles required by pkg-1.3.8_2 for building
.........
................
CC       pkg-update.o
CC       pkg-updating.o
CC       pkg-upgrade.o
CC       pkg-utils.o
CC       pkg-version.o
  CC       pkg-which.o 
CCLD     pkg
../libpkg/.libs/libpkg.so: undefined reference to `elf_getshdrstrndx'
../libpkg/.libs/libpkg.so: undefined reference to `archive_write_free'
../libpkg/.libs/libpkg.so: undefined reference to `archive_read_free'
*** Error code 1

Stop in /usr/ports/ports-mgmt/pkg/work/pkg-1.3.8/src.
*** Error code 1

Stop in /usr/ports/ports-mgmt/pkg/work/pkg-1.3.8.
*** Error code 1

Stop in /usr/ports/ports-mgmt/pkg/work/pkg-1.3.8.
*** Error code 1

Stop in /usr/ports/ports-mgmt/pkg.
*** Error code 1

Stop in /usr/ports/ports-mgmt/pkg.
```

By the time of running above command the /etc/make.conf has set 
	
	



```
WITHOUT_PKGNG=yes
```

This is the Jail @ FreeBSD 8.3-STABLE.
Please, note, that parent Node has exactly the same FreeBSD 8.3-STABLE and it was migrated to PKGNG without any issues.

Any ideas on how to overcome the issue with migration to PKGNG are very appreciated.
Thank you in advance for your time and efforts for being involved in reading and posting answers.


----------



## joint (Oct 24, 2014)

Sorry for this issue-reminder but I have searched for answers at this forum as well as on Google without anything close to bit of happiness and community support. 
Looks like I've done really something wrong to deserve being off-the-road.

Well, kind of stuck in between:

Could not find the possibilities to get things done to the logic end after the first of September with ports-mgmt/portupgrade which was used permanently many years without any major issues.And as you can see 
There is still not the light at the end of the tunnel to get migrate to PKGNG by building the ports-mgmt/pkg.
Any hints and suggestions very appreciated.


----------



## SirDice (Oct 24, 2014)

Try installing the binary version with `pkg bootstrap -f`.


----------



## joint (Oct 26, 2014)

Ok, here is what I'm getting back on:
# `pkg bootstrap -f`

```
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]:
```
`y`

```
Bootstrapping pkg please wait
_http._tcp.pkg.FreeBSD.org
the most recent version of pkg-1.3.7 is already installed

Failed to install the following 1 package(s): /tmp//pkg.txz.GC4wTX
```

and when I'm going further with:
# `pkg -v`

I'm getting this:

```
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]: y
Bootstrapping pkg please wait
_http._tcp.pkg.FreeBSD.org
pkg-static: PACKAGESITE in pkg.conf is no longer supported.  Convert to the new repository style.  See pkg.conf(5)
pkg-static: Cannot parse configuration file!
```

As I'm getting that feedback I follow these steps:
# `rm /usr/local/etc/pkg.conf`
# `echo 'WITH_PKGNG=yes' >> /etc/make.conf`

# `pkg2ng`

```
pkg2ng: Command not found.
```

By the moment on getting above I thought to go for an attempt trying to fix it by binary version install of ports-mgmt/pkg package via the OLD_fashion:
`# pkg_add -r pkg`
for just trying to get `pkg2ng` in the order to be able finally go for the PKG2NG migration.

The OLD_fashion binary package install mode got installed it:
`# pkg_info |grep pkg`

```
pkg-1.2.6           New generation package manager
pkgconf-0.9.6_1     Utility to help to configure compiler and linker flags
```

Now it's time to check if the `pkg` is running by:
# `pkg -v`
and it turns back this:

```
/libexec/ld-elf.so.1: /usr/local/lib/libpkg.so.1: Undefined symbol "posix_fallocate"
```

So, at this moment I went on further trying to update the outdated `pkg-1.2.6` via:
# `portupgrade pkg`
and got back these lines:

```
CC       pkg-which.o
  CCLD     pkg
../libpkg/.libs/libpkg.so: undefined reference to `elf_getshdrstrndx'
../libpkg/.libs/libpkg.so: undefined reference to `archive_write_free'
../libpkg/.libs/libpkg.so: undefined reference to `archive_read_free'
*** Error code 1

Stop in /usr/ports/ports-mgmt/pkg/work/pkg-1.3.8/src.
*** Error code 1

Stop in /usr/ports/ports-mgmt/pkg/work/pkg-1.3.8.
*** Error code 1

Stop in /usr/ports/ports-mgmt/pkg/work/pkg-1.3.8.
*** Error code 1

Stop in /usr/ports/ports-mgmt/pkg.
*** Error code 1

Stop in /usr/ports/ports-mgmt/pkg.
** Command failed [exit code 1]: /usr/bin/script -qa /tmp/portupgrade20141026-14769-fkn57i env UPGRADE_TOOL=portupgrade UPGRADE_PORT=pkg-1.2.6 UPGRADE_PORT_VER=1.2.6 make
** Fix the problem and try again.
** Listing the failed packages (-:ignored / *:skipped / !:failed)
        ! ports-mgmt/pkg (pkg-1.2.6)    (linker error)
```

So, in general if I'm not mistaken it looks like there is something wrong with linking reference to a library file.

Are there any thoughts on how to fix it, please?


----------



## rmoe (Oct 27, 2014)

`elf_getshdrstrndx`, to name one instance, is in the system source in libelf (`"int        elf_getshdrstrndx(Elf *_elf, size_t *_dst);"` in /usr/src/lib/libelf/libelf.h).

Unfortunately, I don't know a lot of details about your system, such as the FreeBSD version, and am therefore left to guessing, but the info you provide suggests to me that your problem is somewhere else/more profound, namely that your system is generally in an inconsistent state.

If you provide more information we might be able to help you better.


----------



## kpa (Oct 27, 2014)

A full run of `mergemaster`, `make delete-old` and `make delete-old-libs` with sources that you know to match your installed system and with make.conf and src.conf double checked for stale/incorrect settings is what I would try first.


----------



## joint (Oct 27, 2014)

rmoe said:


> Unfortunately, I don't know a lot of details about your system, such as the FreeBSD version, and am therefore left to guessing


This is the Jail @ FreeBSD 8.3-STABLE.
Please, note, that parent Node has exactly the same FreeBSD 8.3-STABLE and it was migrated to PKGNG without any issues.
The same NO issues were raised at another 5 jails running within that Node, but this one only.


----------



## ShelLuser (Oct 27, 2014)

Just some ideas here, but in general I can say that pkg shouldn't have issues when used in a jail. So some (maybe obvious) things I'd look out for: Is the port collection fully up to date?  Also; do you have any specific security settings for some of your file systems?

For example; on my system I keep the execute permission off for /tmp and /var/tmp in order to prevent nastiness happening with not to great customer websites. However, I also discovered that sometimes this can prevent a port from installing itself as well.

Finally, also important: how does this jail get its software upgraded?  When upgrading your system I assume you do keep /usr/ports/UPDATING in mind? Because that is the number one cause for problems such as these; failing to follow the instructions in that file which can lead to an inconsistent system.

Hope this can give you some ideas..


----------



## joint (Oct 28, 2014)

ShelLuser said:


> Is the port collection fully up to date?


Yep, sure, even had to remove all of them just recently and then got them all over again by:
`# portsnap fetch extract`
`# portsnap fetch update`



ShelLuser said:


> do you have any specific security settings for some of your file systems?


Well, no, there are no any specific security settings made at that jail instance, i.e. all of the jails were created one by one reflecting the same security settings.

As I've mentioned earlier that I have had the issue with PKGNG migration happened at the only one jail instance while those other five as well as the main Node were migrated to the new package system perfectly.



ShelLuser said:


> When upgrading your system I assume you do keep /usr/ports/UPDATING in mind?


You are spot on, my friend!
I always do that as good practise since the last four years.



ShelLuser said:


> how does this jail get its software upgraded?


Every jail get its software (ports and packages) upgraded by using ports-mgmt/portupgrade but individually, i.e. every jail's ports collection updated within it and considers as private.

And the only difference (in respect of what are installed) between those jails is one of them is using APC caching setup and those others are run under Xcache setup as for PHP requests caching.

Are there any thoughts on what other spots within the system (library files, packages) might be worth to check up for and compare between running a smooth jail with a problematic one?

Just got checked my history notes log for that problematic Jail and it was found that earlier, a month before migration to PKGNG,
It was another issue experienced while building the lang/gcc 
And I did not initiated build of this port by my own intention but it began to build as a dependence to ... but sorry, I did not even notice of what other port had engaged and drawn for that lang/gcc  compiling process.
So, that lang/gcc  compilation never ended successfully since that past moment.
And this problematic Jail has:
`# pkg_info | grep gcc`

```
gcc-ecj-4.5         Eclipse Java Compiler used to build GCC Java
```

while all the rest Jails have:

```
gcc-4.8.3_2                    GNU Compiler Collection 4.8
gcc-ecj-4.5         Eclipse Java Compiler used to build GCC Java
```

Could it be the missing of that build lang/gcc , i.e. `gcc-4.8.3_2` would cause further consequences with initially reported issue on migration to PKGNG?

In case if outcome is: Yes,
  then
- Is it any correct breakout from this catch?
- How to succeed on building the lang/gcc  port but bearing in mind that there is no possibility to build/install anything? - I mean that when the OLD_fashion pkg_* is discontinued but the NEW Package Feature does not running yet (or might it be an attempt try to build from source, as an emergency option left only?)


----------

