In an Arduino-Uno-like design, the ATmega8u2 is used as a USB to Serial Converter, for talking to the ATmega328p "main" microcontroller.You have to program the 8u2 with the USB/Serial firmware, AND you have to program the 328p with the bootloader, before you can "upload" from the Arduino IDE to the 328p. You could also program either or both chips with ISP programming (needing an external "programmer" of some kind), without any prior programming (ISP is how you'd normally put the firmware and bootloader on the chips.)
Note that "normally", the 8u2 does not "program" the 328; it merely provides a communications channel, and the the bootloader in the m328 "self-programs" the chip.